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 );
}
"mylab8.c" 73 lines, 1259 characters
}
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