【发布时间】:2014-08-23 01:41:00
【问题描述】:
如何使 fgets(或类似语句)的输入字符串 S1 等于我声明的静态字符串 S2?
#include <stdio.h>
#include <string.h>
main() {
char s1[80];
char s2[] = "This is a test.";
int l1, l2;
system("clear");
printf("%s\n\n", s2);
printf("Please type exactly the above sentence: ");
fgets(s1,80,stdin);
l1=strlen(s1);
l2=strlen(s2);
printf("\n String entered for S1, have a length of %d:\n %s", l1, s1);
printf("\n String static for S2, have a legnth of %d:\n %s", l2, s2);
if(s1==s2)
printf("\n\nOk! they're with the same length!\n");
else
printf("\n\nNop! They are NOT the same.\n");
return(0);
}
【问题讨论】:
-
您是要比较
l1和l2而不是s1和s2? -
我需要帮助才能了解为什么 s1 和 s2 的字符串不一样,即使您正确输入了“这是一个测试”的确切句子。并寻求我如何能够做到这一点。谢谢你,以及每一个花时间(努力)来研究这个基本问题的人。 :-)