如何将写在TXT文件中的英语题目以结构体数组的形式存储并读取?
上个学期学完了c语言,现在在基于c语言做一个课程练习,遇到了问题,对我来说是瓶颈,做不出来,才请教网上的各位大神.希望走过路过的看看,谢谢了!
以下是我存在txt文件中的三个例题:
1.In ___ a job or adancing in one , the ability to read and comprehend quickly can mean the difference between success and failure.
A getting
B applying
C doing
D offering
B
2.You were working too hard. You'd better keep a ___ between work and relaxation.
A promise
B lead
C balance
D diary
C
3.The dog may be a good companion for the old. ___ , the need to take it for walks may be a disadvantage.
A Besides
B However
C Therefore
D Instead
B
(注:题目从开头一直写,直到写完题目后换行,在下一行写选项A,写完选项A后换行至下一行写选项B,写完选项B后换行至下一行写选项C,写完选项C后换行至下一行写选项D,最后换行写正确选项,再空一行书写题目2.等等)
#define N 100
结构体代码如下:
typedef struct test
{
char problem[N];//存放N个问题
char A[N];//存放N个答案A
char B[N];//存放N个答案B
char C[N];//存放N个答案C
char D[N];//存放N个答案D
char answer[N];//存放N个正确答案
}TEST;
(注:problem[i],A[i],B[i],C[i],D[i],answer[i]构成一个题目.比如当i=1时,可以从文件中读取到上述的题目1,并显示在屏幕上.一开始只读取题目和四个选项,待用户答题后再读出正确答案并显示在屏幕上.)
(注:文件操作时,存和读的时候请用fgets或fputs)
(请附代码,谢谢!)
c语言
结构体
文件操作
文件存和写
typedef
分享到:
------解决方案--------------------
文件读取是按指针形式一个字符一个字符扫描的 不能直接从中读取指定位置的结构体 只能是自己一行一行的读 然后用结构体数组把它存放起来
------解决方案--------------------
参考http://www.cnitblog.com/guopingleee/archive/2009/01/18/53850.html
参考http://hi.baidu.com/lulyon/item/7009fde698587e226cabb8a4
引用:上个学期学完了c语言,现在在基于c语言做一个课程练习,遇到了问题,对我来说是瓶颈,做不出来,才请教网上的各位大神.希望走过路过的看看,谢谢了!
以下是我存在txt文件中的三个例题:
1.In ___ a job or adancing in one , the ability to read and comprehend quickly can mean the difference between success and failure.
A getting
B applying
C doing
D offering
B
2.You were working too hard. You'd better keep a ___ between work and relaxation.
A promise
B lead
C balance
D diary
C
3.The dog may be a good companion for the old. ___ , the need to take it for walks may be a disadvantage.
A Besides
B However
C Therefore
D Instead
B
(注:题目从开头一直写,直到写完题目后换行,在下一行写选项A,写完选项A后换行至下一行写选项B,写完选项B后换行至下一行写选项C,写完选项C后换行至下一行写选项D,最后换行写正确选项,再空一行书写题目2.等等)
#define N 100
结构体代码如下:
typedef struct test
{
char problem[N];//存放N个问题
char A[N];//存放N个答案A
char B[N];//存放N个答案B
char C[N];//存放N个答案C
char D[N];//存放N个答案D
char answer[N];//存放N个正确答案
}TEST;
(注:problem[i],A[i],B[i],C[i],D[i],answer[i]构成一个题目.比如当i=1时,可以从文件中读取到上述的题目1,并显示在屏幕上.一开始只读取题目和四个选项,待用户答题后再读出正确答案并显示在屏幕上.)
(注:文件操作时,存和读的时候请用fgets或fputs)
(请附代码,谢谢!)
------解决方案--------------------
基础的一些文件操作而已!楼主自己先想想思路,整理下基本的代码思路
自己多动手写写,而且需要用的api也都告诉你了!
------解决方案--------------------
没实际编译链接调试,不保证对。仅供参考:
1.In ___ a job or adancing in one , the ability to read and comprehend quickly can mean the difference between success and failure.
A getting
B applying
C doing
D offering
B
2.You were working too hard. You'd better keep a ___ between work and relaxation.
A promise
B lead
C balance
D diary
C
3.The dog may be a good companion for the old. ___ , the need to take it for walks may be a disadvantage.
A Besides
B However
C Therefore
D Instead
B
#include
#include
#define QN 200
#define QNQ "200"
#define AN 50