我刚刚开始用C语言编程,并且正在编写密码/解密程序。用户被要求键入一个存储为char *的短语。问题是程序仅存储字符串的第一个单词,然后忽略它后面的所有内容。下面是获取字符串代码的一部分,然后对其进行分析String只记录第一个字
int maincalc(int k) //The Calculation Function for Cyphering
{
char *s;
s=(char*) malloc(sizeof(100));
printf("Please enter the phrase that you would like to code: ");
fscanf(stdin,"%s %99[^\n]", s);
int i=0;
int n=strlen(s);
while(i<n)
{
if(s[i]>=65&&s[i]<=90) //For Uppercase letters
{
int u=s[i];
int c=uppercalc(u,k);
printf("%c",c);
}
else if(s[i]>=97&&s[i]<=122) //For Lowercase letters
{
int u=s[i];
int c=lowercalc(u,k);
printf("%c",c);
}
else
printf("%c",s[i]); //For non letters
i++;
}
free(s);
printf("\n");
return 0;
}
只需要知道如何做才能让程序确认,不仅整个字符串的第一个字的存在。谢谢
+1因为没有考虑'gets()' – axiom 2013-03-02 13:41:09
我太新了,不能靠近gets()我不希望我的电脑爆炸。 – shea 2013-03-02 14:02:32