fgets读取一行数据直到遇到回车换行结束,经过测试,遇到空格也会结束读取
#include <stdio.h>
#include <math.h>
#define TEST(x) printf("square of " #x " is %d.\n",(x)*(x))
int main(void)
{
char device[256];
char mount_path[256];
char rest[256];
FILE *fp;
char line[1024];
fp = fopen("kkq.txt", "rw");
while(fgets(line, sizeof(line), fp))
{
// line[strlen(line)-1] = '\0';
sscanf(line, "%255s%255s\n", device,mount_path);
printf("==>device:%s mount_path:%s\n",device,mount_path);
}
fclose(fp);
}
kkq.txt内容为123456 abcd
输出结果为:device:123456 mount_path: abcd
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。