这是我的代码,不使用else if:
#include <stdio.h>
main()
{
long s = 0, t = 0, n = 0;
int c;
while ((c = getchar()) != EOF)
if (c == ' ')
++s;
if (c == '\t')
++t;
if (c == '\n')
++n;
printf("spaces: %d tabulations: %d newlines: %d", s, t, n);
}
Run Code Online (Sandbox Code Playgroud)
这是使用else的代码,如果:
#include <stdio.h>
main()
{
long s = 0, t = 0, n = 0;
int c;
while ((c = getchar()) != EOF)
if …Run Code Online (Sandbox Code Playgroud)