如何阅读和处理此类文件 [英] How can I read and process this kind of file

查看:211
本文介绍了如何阅读和处理此类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I 12 0

I 9 1

I 26 0

I 25 2

B 26

P 0

R 25

A

所以,我需要做的是读取一个包含这些字符/数字的文件,每当我遇到一封信时,我都会调用一个函数来处理这封信后面的内容(又名数字)。
例如:
当读I时,我必须将函数调用到 INSERT 特定级别的跳过列表中的某个数字;或者在阅读B时,我需要在跳过列表等中搜索特定的数字。

So, what I need to do is read a file containing these characters/numbers and whenever I encounter a letter, I call a function to process whatever comes after the letter (aka the numbers). For example: When reading "I" I have to call the function to INSERT a certain number in a certain level of a Skip List; or when reading B, I need to search for a specific number in the Skip List, etc.

问题是我从文件中读取真的很糟糕,你能不能伙计们赐教我?

Problem is I'm really bad at reading from a file, can you guys enlighten me?

推荐答案

你可以用c,
i中的文件操作来做这个,我只是给你提示,

You can do this with file operations in c, i am just giving you hints,

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')

with fread() to get whole first line(until '\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

}

这篇关于如何阅读和处理此类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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