有懂GNU c (gmake_tool)的最好来帮帮我呀!(100分)

  • 主题发起人 wspdelphi
  • 开始时间
W

wspdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
有一个文件,名称:jq,内容:
<编码>130501001001000001<姓名>张三的<出生日期>1976-07-17<配偶姓名>李四式
<编码>130501001001000002<姓名>风五<出生日期>1976-08-17<配偶姓名>刘六
我输入000002,然后对文件进行每行查找,找到‘130501001001000002’后,将信息(<编码>130501001001000002<姓名>风五<出生日期>1976-08-17<配偶姓名>刘六)输出。
好心人给个c程序。如果有懂GNU c (gmake_tool)的最好给个GNU的例子,我都调了一周了,快吐血了。本人从没用c实战过。所以是c的菜鸟,^_^。大家帮我呀。
我有一个例子:
FILE * fp;
fp=fopen(&quot;jq0&quot;,&quot;rb&quot;);
istrue=0;
while(!feof(fp))
{
fgets(string,1000,fp);
if (strstr(string,buffer)!=NULL)
{
istrue=1;
while (i<18)
{
womenbm=string;
i++;
}
break;
}
else
istrue=0;
}
fclose(fp);
if(istrue==0)
{
clrscr();
DisplayLine(0, &quot;没有找到该编码的育妇&quot;, ALIGN_CENTER, false);
DisplayLine(1, buffer, ALIGN_LEFT, false);
DisplayOkCancel(MB_CANCEL);
get_key();
return;
}
在WIN-TC中顺利通过,但是在GNU中编译没事,放到pos机上,就不行了。
下面是从pos机读数据的例子:
//从文件中读一条记录
int read_file_block(unsigned char *fnamed, int site, unsigned char *buffer, unsigned int len)
{
int file_handle, ret_int, file_len;
if (check_file_exist(fnamed)==false) {
ShowMessage(&quot;读文件错误&quot;, &quot;没有记录!&quot;, MB_OK,true);
return 0;
}
file_handle=file_open(fnamed, READ_ONLY);
if (file_handle<0) {
ShowMessage(&quot;读文件错误&quot;, &quot;打开文件错误!&quot;, MB_OK,true);
return file_handle;
}
file_len=file_length(file_handle);
if (file_len<site) {
file_close(file_handle);
return 0;
}
ret_int=file_seek(file_handle, site, SEEK_FILE_SET);
if(ret_int!=0) {
file_close(file_handle);
ShowMessage(&quot;读文件错误&quot;, &quot;定位文件错误!&quot;, MB_OK,true);
return ret_int;
}
ret_int=file_read(file_handle,buffer,len);
if(ret_int!=len) {
file_close(file_handle);
ShowMessage(&quot;读文件错误&quot;, &quot;读文件错误!&quot;, MB_OK,true);
return ret_int;
}
file_close(file_handle);
return 1;
}
谁能帮我改改,改成一次性打开文件,然后循环逐行读入数据。直到找到,或到文件尾。
 

Similar threads

顶部