我试图从用户那里获取一些数据并将其发送到gcc中的另一个函数.代码是这样的.
printf("Enter your Name: ");
if (!(fgets(Name, sizeof Name, stdin) != NULL)) {
fprintf(stderr, "Error reading Name.\n");
exit(1);
}
Run Code Online (Sandbox Code Playgroud)
但是,我发现它最后有一个换行符\n.所以,如果我输入John它最终发送John\n.如何删除它\n并发送正确的字符串.
我试图让一个程序让用户输入一个单词或字符,存储它,然后打印它,直到用户再次键入它,退出程序.我的代码看起来像这样:
#include <stdio.h>
int main()
{
char input[40];
char check[40];
int i=0;
printf("Hello!\nPlease enter a word or character:\n");
gets(input);
printf("I will now repeat this until you type it back to me.\n");
while (check != input)
{
printf("%s\n", input);
gets(check);
}
printf("Good bye!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是我不断打印输入字符串,即使用户输入(检查)与原始(输入)匹配.我比较错误吗?