I 12 0
I 9 1
I 26 0
I 25 2
B 26
P 0
R 25
A
所以,我需要做的是读取包含这些字符/数字的文件,每当遇到字母时,我都会调用一个函数来处理字母后面的任何内容(也称为数字)。
例如:
当读取“I”时,我必须调用函数 INSERT
跳过列表的特定级别中的特定数量;或者在读B时,我需要在Skip List中搜索特定的号码等。
问题是我真的不擅长读取文件,你们能启发我吗?
最佳答案
你可以用c中的文件操作来做到这一点, 我只是给你提示,
FILE *pFilePtr; // file pointer(handle of file)
pFilePtr = fopen(argv[1],"r");
//define buffer to store data read line by line data
char buf[32]={0};
//Now you can run a while loop to read entire file
使用 fread() 获取整个第一行(直到 '\n')
while(!feof(pFilePtr))
{
if(NULL != fgets(buf,32,pFilePtr))
// perform string operation on buffer to extract letters and digits
// and according to that call functions you need
}
关于c - 我怎样才能读取和处理这种文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496440/