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