john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file read conf file

/* John Pfeiffer 2010-08 read a conf file into an array 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINEMAX 1024
#define BUFFERMAX 1024

int main( int argc , char* argv[] )
{   
    int linecounter = 0;
    char buffer [ BUFFERMAX ][ LINEMAX ] ;
    FILE* fptr;
    fptr = fopen( "conf.txt" , "r" );

    if( fptr == NULL )
    {    fprintf( stderr , "\nError opening configuration file\n");
         exit(1);
    }

    memset( buffer , '\0' , sizeof( buffer) );


    while( ! feof(fptr) )
    {   
        fgets( buffer[ linecounter ] , LINEMAX , fptr);
        fputs( buffer[ linecounter ] , stdout );
        linecounter++;        
    }

    fclose( fptr );    
    return 0;
} /* end main */

  • « mingw msys compile open source code on windows
  • speech recognition julius voxforge commands »

Published

Aug 8, 2010

Category

c

~74 words

Tags

  • c 95
  • conf 2
  • file 92
  • read 14