473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Pointer to a 30 MB file

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?

Sep 30 '06 #1
10 2060
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

Sep 30 '06 #2

Robert Gamble wrote:
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.

Sep 30 '06 #3
pkirk25 wrote:
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.

Sep 30 '06 #4
pkirk25 wrote:
Robert Gamble wrote:
>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.
Sep 30 '06 #5
pkirk25 said:

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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 30 '06 #6
pkirk25 wrote:
Robert Gamble wrote:
>>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.

--
Eric Sosman
es*****@acm-dot-org.invalid
Sep 30 '06 #7
>
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/Sho...29714&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.

Sep 30 '06 #8
>
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

Sep 30 '06 #9
pkirk25 wrote:
>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/Sho...29714&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.
Sep 30 '06 #10
pkirk25 wrote:
>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
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.
Sep 30 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
7
by: W. Van Hooste | last post by:
Hello, I'm writing a program to display somme values as nice X graphics for a special purpose. Under here is part of my main code and part of the code to gather the sample data. the sample data...
3
by: Don Pasquale | last post by:
The following function intends to delete "numberoflines" lines from a text file, named "s" (string pointer) and pointed to by file pointer "fp", starting from line "line". Now, the function...
9
by: Abhishek | last post by:
Hello everybody, I am reading a file into a char array. Because of which we cannot give array size in GBs of data. Is there a technique through which i can cast a file pointer to char pointer...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.