寰宇榛仁 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 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
    • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
    • ¥30 NIRfast软件使用指导
    • ¥20 matlab仿真问题,求功率谱密度
    • ¥15 求micropython modbus-RTU 从机的代码或库?
    • ¥15 django5安装失败
    • ¥15 Java与Hbase相关问题
    • ¥15 后缀 crn 游戏文件提取资源
    • ¥20 bash代码推送不上去 git fetch origin master #失败了
    • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开