#include <stdio.h>
#include <string.h>
#include <Windows.h>
#pragma warning(disable:4996)
int main(void) {
char word[64];
int count=0;
int length=0;
printf("请输入任意多个单词:");
while (1) {
scanf("%s", word);
if (word == "-1"){
break;
}
}
count++;
length += strlen("word");
printf("一共有%d个单词\n", count);
printf("一共有%d个字符\n", length);
system("pause");
return 0;
}
使用函数strcmp(s1,s2)判断两个字符串数组是否相等
改成
if (strcmp(word,"-1")==0)
完整的已改好:如有帮助,请点击【采纳该答案】按钮支持一下,谢谢!以后有什么问题可以互相交流。
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#pragma warning(disable:4996)
int main() {
char word[64];
int count=0;
int length=0;
printf("请输入任意多个单词:");
while (1) {
scanf("%s", word);
if (strcmp(word,"-1")==0){
break;
}
count++;length += strlen(word);
}
printf("一共有%d个单词\n", count);
printf("一共有%d个字符\n", length);
system("pause");
return 0;
}
代码修改如下
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
char s[10];
while (1)
{
scanf("%s", s);
if (!strcmp(s, "-1"))
{
break;
}
}
};
有帮助望采纳~