Help needed to count lines between preprocessor directives

J

James Kew

char tstr[10]; [...]
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated

Or indeed even needed -- why seek to the beginning a file you've just
opened?
for(;strcmp(tstr,"#ifdef win32")!=0;fgets(cfile,tstr));//value for strcmp

tstr is undefined for the first iteration here.

James
 
M

MikeyD

char tstr[10];
[...]
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated

Or indeed even needed -- why seek to the beginning a file you've just
opened?

To make sure the cursor is at the start. I don't know if it's necessary or
not.
strcmp

tstr is undefined for the first iteration here.
Okay then, replace char tstr[10]; with char tstr[]="aaaaaaaaaaa";
 
B

Barry Schwarz

char tstr[10]; [...]
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated

Or indeed even needed -- why seek to the beginning a file you've just
opened?

To make sure the cursor is at the start. I don't know if it's necessary or
not.

What cursor?

What does you manual say that fopen will do if it successfully opens a
file for read?



<<Remove the del for email>>
 
M

MikeyD

Barry Schwarz said:
char tstr[10];
[...]
cfile=fopen(filepath, "r");
fseek(cfile,SEEK_SET);//not sure if this is correctly formulated

Or indeed even needed -- why seek to the beginning a file you've just
opened?

To make sure the cursor is at the start. I don't know if it's necessary or
not.

What cursor?

The file cursor
What does you manual say that fopen will do if it successfully opens a
file for read?
It says it will return a pointer to that file. Then it moves on to fclose().
 
M

Mark McIntyre

The file cursor

its called the file position indicator in the C standard. "cursor" is
a term more often associated with databases or screens.
It says it will return a pointer to that file.

It doesn't mention the effect of the 2nd parameter to fopen()? If it
came with your compiler, complain to the vendor, otherwise throw it
away and get a proper manual. For any decent manual will tell you
about that parameter and thus explain where the position indicator is
set to when you open the file.
 
M

MikeyD

What does you manual say that fopen will do if it successfully opens a
It doesn't mention the effect of the 2nd parameter to fopen()? If it
came with your compiler, complain to the vendor, otherwise throw it
away and get a proper manual. For any decent manual will tell you
about that parameter and thus explain where the position indicator is
set to when you open the file.

What I can remember of my manual entry. I may have just forgotten about the
file position indicator.
"...fopen([const?]char* filename, const char* mode)
Opens the file <i>filename</i> in the mode indicated by <i>mode</i>. Mode
list:
<table>
r Opens the file for reading
w Opens the file for writing
.....
</table>
<b>Returns:</b> A pointer to that file.
fclose(FILE* f)..."
 

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,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top