23,125
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
该函数从buff中读出一行,并打印到标准输出上
传入参数为此次读取开始位置
返回下次读取开始位置
*/
char* getLine(char* buff)
{
char* pos = buff;
char tmp[20];
memset(tmp, 0, sizeof(tmp));
//该函数将缓冲区中的一行数据格式化到tmp中
sscanf(pos, "%s", tmp);
printf("%s\n", tmp);
pos += strlen(tmp);
pos++;
return pos;
}
int main()
{
char buff[1024];
char* pos = buff;
memset(buff, 0, sizeof(buff));
sprintf(buff, "%s", "aaaa\nbbbb\nccccc\n");
pos = getLine(pos);
pos = getLine(pos);
pos = getLine(pos);
return 0;
}