[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
|
- Re: [hlcoders] Question about t... Dave R. Meyers
- Re: [hlcoders] Question about t... omega
- Re: [hlcoders] Question about t... Dave R. Meyers
- [hlcoders] Water currants??? Dave R. Meyers
- [hlcoders] 'using' an object _Phantom_
- Re: [hlcoders] 'using' an objec... botman
- Re: [hlcoders] 'using' an objec... _Phantom_
- [hlcoders] Alternate Mod Dir Nicemice
- Re: [hlcoders] Alternate Mod Di... Dave R. Meyers
- Re: [hlcoders] Question about the EULA again Dave R. Meyers
- Re: [hlcoders] file reading from... Varlock
- Re: [hlcoders] file reading from... Christopher Long
- Re: [hlcoders] file reading from... Christopher Long
- Re: [hlcoders] file reading from... Stuart Walsh
- Re: [hlcoders] file reading from... Ralph Hartley
- Re: [hlcoders] file reading from... Stuart Walsh
- Re: [hlcoders] file reading from... botman
- Re: [hlcoders] file reading from... Stuart Walsh
- Re: [hlcoders] file reading from... Cortex
- Re: [hlcoders] file reading from... Christopher Long