Pointer to a 30 MB file

P

pkirk25

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?
 
R

Robert Gamble

pkirk25 wrote:

[snip]
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?

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

Robert Gamble
 
P

pkirk25

Robert said:
pkirk25 wrote:

[snip]
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?

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

Robert Gamble

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.
 
C

clayne

pkirk25 said:
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.
 
J

Joe Estock

pkirk25 said:
Robert said:
pkirk25 wrote:

[snip]
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?
Take a look at the rewind() function. You may also find the
fseek/ftell and fgetpos/fsetpos functions useful.

Robert Gamble

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.

Are you sure the call to malloc is not returning NULL? If so, that's
certainly grounds for UB.
 
R

Richard Heathfield

pkirk25 said:

char *temp_string = malloc(254);

Where's the check that this allocation succeeded?

Or were you trusting your computer never, ever to run out of memory, no
matter how much you ask it for and how many times you ask?
 
E

Eric Sosman

pkirk25 said:
Robert said:
pkirk25 wrote:

[snip]

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?

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

Robert Gamble


2 files with identical code

char *temp_string = malloc(254);

A strange "magic number." One hopes it is at least as
large as MAXLEN (and one wonders why MAXLEN wasn't used). One
might also wish for a check to see whether malloc() succeeded.
rewind(auctioneer_lua);

One guesses that auctioneer_lua is a FILE* value. Has it
been initialized? To something other than NULL?
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.

After your break, consider whether someone seeing only the
snips and clips of your code has enough information to go on.
Do you know of the fable about the blind men and the elephant?
Each can feel a different part of the beast, and they all draw
vastly different conclusions as to its nature: like a snake, like
a tree, like a house, and so on. Don't force us to pet pachyderms.
 
P

pkirk25

Are you sure the call to malloc is not returning NULL? If so, that's
certainly grounds for UB.

Printf returns NULL for it.

My real problem was this:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=129714&SiteID=1

"Debugging does not work though when using the General/Empty Project
template to create a new project."

So I created a new project in the exact steps you need and I can now
debug.

I hope to learn to use the debugger without too many tears.
 
P

pkirk25

Take a look at the rewind() function. You may also find the
fseek/ftell and fgetpos/fsetpos functions useful.
rewind() causes the crash. I don't understand the debugger message.

- _tmpfname 0x00000000 <Bad Ptr> char *


CXX0030: Error: expression cannot be evaluated
 
J

Joe Estock

pkirk25 said:
Printf returns NULL for it.

My real problem was this:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=129714&SiteID=1

"Debugging does not work though when using the General/Empty Project
template to create a new project."

So I created a new project in the exact steps you need and I can now
debug.

I hope to learn to use the debugger without too many tears.

This doesn't sound like a debugger I would trust then. A debugger should
allow you to debug any code without regard to how the code was created.
 
J

Joe Estock

pkirk25 said:
rewind() causes the crash. I don't understand the debugger message.

- _tmpfname 0x00000000 <Bad Ptr> char *


CXX0030: Error: expression cannot be evaluated

The problem is simple. You obviously have an invalid pointer as
*something*. Without seeing your actual code I have no idea what you are
doing wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top