寰宇榛仁 2022-03-04 16:17 采纳率: 66.7%
浏览 6
已结题

C Primer Plus (第6版)中文版 P299中程序清单11.23 quit_chk.c程序,运行错误

C Primer Plus (第6版)中文版 P299中程序清单11.23 quit_chk.c程序,运行错误,表达式必须是可修改的左值,麻烦各位,怎么修改才不会有错误

#include <stdio.h>
#include <string.h>
#define SIZE 80
#define LIM 10
#define STOP "quit"
char* s_gets(char* st, int n);

int main(void)
{
    char input[LIM][SIZE];
    int ct = 0;

    printf("Enter up to %d lines(type quit to quit):\n", LIM);
    while (ct < LIM && s_gets(input[ct], SIZE) != NULL && strcmp(input[ct], STOP) != 0)
    {
        ct++;
    }
    printf("%d strings entered\n", ct);

    return 0;
}

char* s_gets(char* st, int n)
{
    char* ret_val;
    int i = 0;

    ret_val = fgets(st, n, stdin);
    if (ret_val)
    {
        while  (st[i] != '\n' && st[i] = '\0')  //表达式必须是可修改的左值
            i++;
        if (st[i] == '\n')
            st[i] = '\0';
        else
            while (getchar() != '\n')
                continue;
    }
    return ret_val;
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 3月12日
    • 创建了问题 3月4日

    悬赏问题

    • ¥15 征集Python提取PDF文字属性的代码
    • ¥15 有偿求苍穹外卖环境配置
    • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
    • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
    • ¥15 clousx6整点报时指令怎么写
    • ¥30 远程帮我安装软件及库文件
    • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
    • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
    • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
    • ¥15 Android studio 无法定位adb是什么问题?