啦啦啦拉拉裤 2021-11-22 12:11 采纳率: 69.4%
浏览 57
已结题

C语言问题 read a line在代码中添加

该函数应该从指定的流中读取一行输入。更准确地说,它应该:从流中读取至多小于 size 的字符并将它们存储到 s 指向的缓冲区中。阅读在 EOF 或换行符后停止。如果读取换行符,则将其存储到缓冲区中。终止空字节('\0')存储在缓冲区中的最后一个字符之后。需要写主函数。

img

img

img

#include <stdio.h>

#include "get_string.h"

// print a line from stream using fgetc (only)
// reads  in at  most one less than size characters from stream and stores them into the
// buffer pointed to by s.  Reading stops after an EOF or a newline.  If a newline is read, it  is
// stored  into  the buffer.  A terminating null byte ('\0') is stored after the last character in the buffer.
void get_string(char *s, int size, FILE *stream) {

    // PUT YOUR CODE HERE

}

  • 写回答

1条回答 默认 最新

  • CSDN专家-Time 2021-11-22 12:40
    关注
    #include <stdio.h>
    #include <ctype.h>
    int main(void)
    {
        char ch;
    
        ch = getchar();
        while (ch != '\0')
        {
            if (isalpha(ch))
                putchar(ch + 1);
            else
                putchar(ch);
            ch = getchar();
        }
        putchar(ch);    //打印换行字符
        return 0;
    }
    

    用这个玩

    sprintf(s,"%.*s",len,szBuf);
    这个函数也能赋值字符串
    

    img

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月29日
  • 创建了问题 11月22日