[CODE]
 
#include <stdio.h>        // not sure which one or both of these two includes you need
#include <stdlib.h>
 
FILE *pFile = NULL;
 
void MyFunction( void )
{
    pFile = fopen( "filename.txt", "r" );        // "r" means read-mode
 
    if( !pFile )
        // error
 
    char line[1024];
 
    fgets( line, 1024, pFile );
 
    fclose( pFile );
}
 
[/CODE]
 
    This code will open "filename.txt" in read-mode. You should do something if it doesn't load properly (where there's the // error comment). Then it reads the FIRST 1024 CHARACTERS or UNTIL A NEWLINE IS REACHED. The fgets function automatically reads up to the number of characters you pass it (in this case 1024) or until a newline character is reached. Now you can use line as you wish. Finally, the code closes the file.
 
- Varlock
----- Original Message -----
Sent: Saturday, January 05, 2002 7:39 PM
Subject: [hlcoders] file reading from...

gEngfuncs.COM_ParseFile takes tokens from the file and with it i can keep grabbing tokens but each token is delimited by white space.
 
char* pFile = gEngfuncs.COM_LoadFile("commandmenu.txt", 5, NULL);
 
pFile points to commandmenus contents so i have a pointer to whats in the commandmenu.txt but thats all of it :/.
 
What i was after was if there is a way to grab from a file one line at a time until it hits the newline character '\n'.
 
i have done it so far with grabbing chunks one at a time checking each character to see if its a new line then setting back the location read... it works but i don't like the way i have done it :(.
 
All i was after is if there is a better way to read one line at a time till the end line char is reached..... or do i have to start including fstream.h to start doing this type of stuff?
 
also another thing is i was after what each of the variables COM_LoadFile takes is?
 
("commandmenu.txt", 5, NULL);
i realise the first string is the file to draw it from
dunno what the 5 is??? someone enlighten me
and from looking i am guess where NULL is you can send a length variable to
have returned the length of the file or something?? but i am not sure only NULL seems to be used everywhere.
 
thanks to anyone that can help.

Reply via email to