帮我看看🙏🙏😭😭为什么我跳不出循环

#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;
}

img

代码修改如下

#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;
        }
    }
};

img

有帮助望采纳~

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632