文件输入/输出用C格式化 [英] File input/output in C unformatted

查看:165
本文介绍了文件输入/输出用C格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typedef char string20[21];

struct x{
string20 a;
string20 b;
string20 c;
};

如何扫描文本文件和它们的值存储在我的结构?我想不出如何做到这一点,顺便说一句,我刚学我一个简单的方法/ O无法找到互联网上的任何好的教程,请帮助
文件格式为:

How do I scan a text file and store their values on my structure? I can't think of an easy way on how to do this and btw I'm just learning I/O can't find any good tutorial on internet please help the file format is:

3
FCODE=random
FKEY=shit
FSRC=hi

如何在一个存储随机等......我知道我应该使用的strcpy ofcourse

how do i store "random" in a and etc... I know I should use strcpy ofcourse

推荐答案

使用与fgets 函数一行。

 eg: fgets(buf, MAX_LINE_SIZE, my_io);

使用和strchr strtok的来找到确切的数据。

Use strchr or strtok to find exact data.

 eg: ptr = strchr(buf, '=');

复制到你的结构

 eg: strcpy(my_structy.ele, ptr);

PS:不要忘了验证。请参考手册页

PS: don't forget validations. refer man pages

这篇关于文件输入/输出用C格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆