reading, editing and creating a new file

This is a discussion on reading, editing and creating a new file within the C Programming forums, part of the General Programming Boards category; My program should at the moment read from a file called input, create two new files called east and west. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    45

    reading, editing and creating a new file

    My program should at the moment read from a file called input, create two new files called east and west. And then print Roster number x for each player. Right now I am working on how to break up each word in the input file into tokens. and print them off in this order.

    Roster# Lastname, Firstname, Hometeam, Scoring average

    my input file is

    Code:
    Joseph Stevens Boys 11 20 5
    Jamie Stevens Girls 22 18 6
    Tony Waters Boys 33 22 7
    Sally Smith Girls 44 33 8
    My program is:

    Code:
    int main ( void )
    {
    char str [ 80 ];
    char first;
    char last;
    char *token;
    int points;
    int games;
    int number;
    int x;
    int roster;
    int y;
    int a = 0;
    FILE * input, * east, * west;
    char array [ 81 ];
    char string [ 80 ] = "Hello My Name is Ben";
    
    if ( ( input = fopen ( "input", "r" ) ) == NULL )
    {
            printf ( "Cannot open file\n" );
            exit ( 1 );
    }
    
    if ( ( east = fopen ( "east", "w" ) ) == NULL )
    {
            printf ( "Cannot open file\n" );
            exit ( 1 );
    }
    
    if ( ( west = fopen ( "west", "w" ) ) == NULL )
    {
            printf ( "Cannot open file\n" );
            exit ( 1 );
    }
    
    x = -1;
    while ( ! feof ( input ) )
            {
            fgets (str, 80, input );
            x ++;
            }
    y = x + 1;
    for (roster = 1; roster < y; roster ++)
            {
            fprintf (east, "Roster# is %d\n", roster);
            fprintf (west, "Roster# is %d\n", roster);
            }
    fgets (str, 80, input );
    
    stringtoken ( str );
    
    }
    
    
    int stringtoken ( char string )
    
    {
    char *token;
    
       printf( "Tokens:\n" );
       /* Establish string and get the first token: */
       token = strtok( string, " ,\n\t" );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, " ,\n\t" );
       }
    }
    And my error when I try to compile is

    mylab8.c:60: warning: type mismatch with previous implicit declaration
    mylab8.c:53: warning: previous implicit declaration of `stringtoken'
    mylab8.c: In function `stringtoken':
    mylab8.c:65: warning: assignment makes pointer from integer without a cast
    mylab8.c:71: warning: assignment makes pointer from integer without a cast

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    shouldn't it be
    Code:
    int stringtoken ( char *string )
    ?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    you mean just put a * in front of it?

    Tried that and it didnt change the warning messages

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    hope you changed the definition AND declaration of the function so they match one another
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating class instance from a file
    By Callith in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2004, 08:03 PM
  2. .rc and resource.h file editing
    By killdragon in forum C++ Programming
    Replies: 8
    Last Post: 08-31-2004, 01:27 PM
  3. registry editing for creating files
    By jverkoey in forum Windows Programming
    Replies: 2
    Last Post: 04-04-2003, 06:43 PM
  4. Creating a prog to edit files with certin extention
    By destroyer32428 in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2001, 02:08 AM

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