Ejemplo n.º 1
0
int main( int argc, char *argv[] )
{
	char * line;
	char **tokensArray;
	int tokenCnt=0;

	FILE * inFile = fopen( argv[1], "r" );
	if (!inFile)
	{
		fprintf(stderr,"Can't open %s for input. Program terminating!\n",argv[1] );
		exit( EXIT_FAILURE );
	}
	while (fgetline_123( &line, inFile ) )
	{
		printf("line: %s\n", line );
		tokensArray = split( line, &tokenCnt ); /* rets ptr to full array of strings */
		printTokensArray( tokensArray, tokenCnt );
		free( line );
		freeTokensArray( tokensArray, tokenCnt ); /* frees the tokens AND the array of pointers - just like lab 3 */
	}
	fclose(inFile);
	return 0;
}
Ejemplo n.º 2
0
/*
   The |getline_123| function is the same as the |fgetline_123|
   function, except that |stream| is given the value of |stdin|.
*/
char *getline_123(char **p)
{
    return fgetline_123(p, stdin);
}