E
Eric
I have a book Learn C in 21 days. But I'm using visual C++ as the
compiler.
Here is my code. What do I need to change to make it work with Visual
C++.
// list_it.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void display_usage(void);
int line;
int _tmain(int argc, _TCHAR* argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)
if( argc < 2)
{
display_usage();
exit(1);
}
/* if (( fp = fopen( argv[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!, argv[1] );
exit(1);
}
*/
line = 1;
while( fgets( buffer, 256, fp ) != NULL )
fprintf( stdout, "%4d:\t%s", line++, buffer );
fclose(fp);
return 0;
}
void display_usage(void)
{
fprintf(stderr, "\nProper Usage is: " );
fprintf(stderr, "\n\nLIST_IT filename.ext\n" );
}
Thanks,
Eric
compiler.
Here is my code. What do I need to change to make it work with Visual
C++.
// list_it.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void display_usage(void);
int line;
int _tmain(int argc, _TCHAR* argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)
if( argc < 2)
{
display_usage();
exit(1);
}
/* if (( fp = fopen( argv[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!, argv[1] );
exit(1);
}
*/
line = 1;
while( fgets( buffer, 256, fp ) != NULL )
fprintf( stdout, "%4d:\t%s", line++, buffer );
fclose(fp);
return 0;
}
void display_usage(void)
{
fprintf(stderr, "\nProper Usage is: " );
fprintf(stderr, "\n\nLIST_IT filename.ext\n" );
}
Thanks,
Eric