View Code of Problem 58

#include <stdio.h>
#include <string.h>
int main()
{
     int i=0,n=0;
     char a[100];
     gets(a);
     for(i=0;i<strlen(a);++i)
     {
     if(a[i]!' '&&(a[i+1]==" "||a[i+1]=='\0'))
       //注意右边条件
       n++;
     
     }
     printf("%d",n);
}
/*
Main.c: In function 'main':
Main.c:7:6: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
      gets(a);
      ^
Main.c:10:13: error: expected ')' before '!' token
      if(a[i]!' '&&(a[i+1]==" "||a[i+1]=='\0'))
             ^
Main.c:12:8: error: stray '\357' in program
        n++;
        ^
Main.c:12:8: error: stray '\274' in program
Main.c:12:8: error: stray '\233' in program
Main.c:14:6: error: expected ';' before '}' token
      }
      ^
*/

Double click to view unformatted code.


Back to problem 58