File Operations (2)

This is a discussion on File Operations (2) within the C Programming forums, part of the General Programming Boards category; Here is the compiler problems to my program. I am using MSDEV on Win2k pro. This is going along on ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > 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.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > 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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 06:28 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21