扫描后fget不工作#include <stdio.h>#include <string.h>#include <ctype.h>void delspace(char *str);int main() {
int i, loops;
char s1[101], s2[101];
scanf("%d", &loops);
while (loops--) {
fgets(s1, 101, stdin);
fgets(s2, 101, stdin);
s1[strlen(s1)] = '\0';
s2[strlen(s2)] = '\0';
if (s1[0] == '\n' && s2[0] == '\n') {
printf("YES\n");
continue;
}
delspace(s1);
delspace(s2);
for (i = 0; s1[i] != '\0'; i++)
s1[i] = tolower(s1[i]);
for (i = 0; s2[i] != '\0'; i++)
s2[i] = tolower(s2[i]);
if (strcmp(s1, s2) == 0) {
printf("YES\n");
}
else {
printf("NO\n");
}
}
return 0;}void delspace(char* str) {
int i = 0;
int j = 0;
char sTmp[strlen(str)];
while (str[i++] != '\0') {
if (str[i] != ' ') {
sTmp[j++] = str[i];
}
}
sTmp[j] = '\0';
strcpy(str, sTmp);}在我输入“循环”之后,“S1”自动被分配了一个空行。这是怎么发生的?我肯定我的键盘工作得很好。
3 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
scanf()
\n
fgets()
fgets()
sscanf()
元芳怎么了
TA贡献1798条经验 获得超7个赞
scanf
int c;do{ c = getchar();}while(c != EOF && c != '\n');
- 3 回答
- 0 关注
- 549 浏览
添加回答
举报
0/150
提交
取消