打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
fgets函数
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
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
字符串输入输出函数 fputs fgets
查找USB设备
区分C语言中getch、getche、fgetc、getc、getchar、fgets、g...
php Readfile vs include
Linux下读写速度测试 - [编程]
文件操作 FILE结构体(C语言版)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服