#include <bits/stdc++.h>
using namespace std;
int main()
{
int ans=0;
char ch[6];
gets(ch);
for(int i=0;i<strlen(ch);i++)
{
if(ch[i]==' ') ans++;
}
printf("%d",strlen(ch)-ans);
return 0;
}
之后出现了
/tmp/compiler_wxzpu2qd/src: 在函数‘int main()’中:
/tmp/compiler_wxzpu2qd/src:7:2: 错误:‘gets’ was not declared in this scope; did you mean ‘fgets’?
7 | gets(ch);
| ^~~~
| fgets
/tmp/compiler_wxzpu2qd/src:8:15: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
8 | for(int i=0;i<strlen(ch);i++)
| ~^~~~~~~~~~~
/tmp/compiler_wxzpu2qd/src:12:11: 警告:格式 ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
12 | printf("%d",strlen(ch)-ans);
| ~^ ~~~~~~~~~~~~~~
| | |
| int size_t {aka long unsigned int}
| %ld
这样的东西该怎么办