-
File Operations (2)
Here is the compiler problems to my program. I am using MSDEV on Win2k pro. This is going along on what I wrote previously. I have noted where the problem is occurring, and I still have holes on where to program this program.
Thank you for your help!
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define DELIMS " \n.,;:!?-_/"
#define MAX_LEN 80
int main( void )
{
FILE *fp_in , *fp_out;
char line[ 81 ] , infile[ 20 ] , outfile[ 20 ];
char *token;
int drop_flag , read_count = 0 , drop_count = 0 , keep_count = 0 ;
int k ;
/* this will open the infile and read it only if
* the file does not exist, it will continue to prompt
* until the user gives it a valid file */
do
{
printf("Enter an input filename >> ");
scanf( "%s" , infile );
} while( (fp_in = fopen( infile , "r" )) == NULL );
do
{
printf("\nEnter an output filename >> ");
scanf( "%s" , outfile );
/* if( (fp_out = fopen( outfile , "r" )) != NULL
{
printf( "\nFile %s exists\n" , outfile );
fclose( fp_out );
exit( 0 );
}
fclose( fp_out ); */
} while( (fp_out = fopen( outfile , "w" )) == NULL );
printf("\nBegin...\n\n" );
fprintf( fp_out , "\nBegin...\n\n" );
for( ; fgets( infile , MAX_LEN + 1 , fp_in ) != NULL ; ++ read_count )/***errorC2198 : fgets : too few actual parameters***/
{
strcpy( outfile , instring );
token = strtok( infile , DELIMS );
for( drop_flag = 0 , token != NULL , token = strtok( NULL , DELIMS )
{
/*token[ 0 ] = to*/
for( k = 0 ; token[ k ] != "\0" ; ++k )/**warningC4047 !=: int iffers in levels of indirection from "char"[2]***/
{
token[ k ] = folower( token[ k ] );
if( strcmp( token, "drop" ) == 0 )
{
drop_flag = 1;
break;
}
if( drop_flag == 0 )
{
printf("\nKeep line %s\n\n", outfile );
fprintf( fp_out ,"%s", outfile );
++ keep_count;
}
else
{
printf("\n Else...\n\n" );
++ drop_count;
}
}
printf("\n( %d , %d , %d )\n" , read_count , keep_count , drop_count );
}
warningC4047 errorC2198
-
> for( k = 0 ; token[ k ] != "\0" ; ++k )/
The problem is because you're using a string value instead of a single character. Use '\0' instead. Just use the same thread also rather than making new ones for the same project.
Quzah.
-
> for( ; fgets( infile , MAX_LEN + 1 , fp_in ) != NULL
You're lying about the size of the buffer
fgets( infile, sizeof(infile), fp_in )
Then make the infile array as big as you want.
> for( drop_flag = 0 , token != NULL , token = strtok( NULL , DELIMS )
This needs ;
> token[ k ] = folower( token[ k ] );
Perhaps tolower?