指向30 MB文件的指针 [英] Pointer to a 30 MB file

查看:52
本文介绍了指向30 MB文件的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while(1)

{

fgets(temp_string,MAXLEN,auctioneer_lua);


/ *检查我们do ave一个有效的数据输入文件* /

if(strstr(temp_string," AuctioneerHistoryDB"))

{

/ *这是一个有效的文件* /

printf("%s\ n",temp_string);

j = items_list(auctioneer_lua);


// j = read_auctioneer_lua(source_file_name);

休息;

}

/ *许多其他东西* /

}


这个测试工作正常但它传递指针的位置是

" AuctioneerHistoryDB"找到。


除了在文件顶部搜索toekn之外,还有一种方法

将指针重置为文件顶部没有关闭和

重新打开它?

while (1)
{
fgets(temp_string, MAXLEN, auctioneer_lua);

/* check that we do ahve a valid data input file */
if (strstr(temp_string, "AuctioneerHistoryDB"))
{
/* this is a valid file */
printf("%s\n", temp_string);
j = items_list(auctioneer_lua);

// j = read_auctioneer_lua(source_file_name);
break;
}
/* lots of other stuff */
}

This test works fine BUT it passes on the pointer with the line where
"AuctioneerHistoryDB" is found.

Other than searching for a toekn at the top of the file, is ther a way
to reset the pointer to the top of the file without closing and
re-opening it?

推荐答案

pkirk25写道:


[snip]
pkirk25 wrote:

[snip]

除了在文件顶部搜索toekn之外,还有其他方式

将指针重置为文件顶部而不关闭,并重新打开它?
重新打开它?
Other than searching for a toekn at the top of the file, is ther a way
to reset the pointer to the top of the file without closing and
re-opening it?



看一下rewind()函数。您可能还会发现

fseek / ftell和fgetpos / fsetpos函数很有用。


Robert Gamble

Take a look at the rewind() function. You may also find the
fseek/ftell and fgetpos/fsetpos functions useful.

Robert Gamble




Robert Gamble写道:

Robert Gamble wrote:

pkirk25写道:


[ snip]
pkirk25 wrote:

[snip]

除了在文件顶部搜索toekn之外,还有一种方法

将指针重置为顶部没有关闭的文件和

重新打开它?
Other than searching for a toekn at the top of the file, is ther a way
to reset the pointer to the top of the file without closing and
re-opening it?



看一下rewind()函数。您可能还会发现

fseek / ftell和fgetpos / fsetpos函数很有用。


Robert Gamble


Take a look at the rewind() function. You may also find the
fseek/ftell and fgetpos/fsetpos functions useful.

Robert Gamble



2个相同代码的文件


char * temp_string = malloc(254);

rewind(auctioneer_lua);

fgets(temp_string,MAXLEN,auctioneer_lua);

printf(请再试一次);

返回0;


在1中,这会导致立即崩溃 - printf永远不会出现。在

其他,它工作正常。


叹气 - 休息时间。

2 files with identical code

char *temp_string = malloc(254);
rewind(auctioneer_lua);
fgets(temp_string, MAXLEN, auctioneer_lua);
printf("Please try again\n");
return 0;

In 1, this causes immediate crash - the printf never appears. In the
other, it works fine.

Sigh - time for a break.

pkirk25写道:
pkirk25 wrote:

char * temp_string = malloc(254);

rewind(auctioneer_lua);

fgets(temp_string,MAXLEN,auctioneer_lua);

printf(请再试一次);

返回0;


在1中,这会导致立即崩溃 - printf永远不会出现。在

其他,它工作正常。


叹气 - 休息时间。
char *temp_string = malloc(254);
rewind(auctioneer_lua);
fgets(temp_string, MAXLEN, auctioneer_lua);
printf("Please try again\n");
return 0;

In 1, this causes immediate crash - the printf never appears. In the
other, it works fine.

Sigh - time for a break.



更合适的是,休息和调试器。


如果您没有在编写的代码中轻松发现内容 - 你需要踩过调试器,直到你强制错误为止。还有其他的东西

是一个痛苦的教训。

More appropriately, a break AND a debugger.

If you''re not spotting things easily in the written code - you need to
be stepping through a debugger until you force the error. Anything else
is a lesson in pain.


这篇关于指向30 MB文件的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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