I am having hard time testing this function, can you please show me how to use the sprintf and make the average ?
here's my code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FILENAME "input.dat"
void FileProcess(void);
int main ( void )
#include <string.h>
#define FILENAME "input.dat"
void FileProcess(void);
int main ( void )
{
char fname [21];
printf("Enter file name: ");
scanf("%s", fname);
if (strcmp ( fname, FILENAME ))
{
printf("Unable to open file specified!\n");}
else
{
FileProcess();
}
}
void FileProcess (void)
{
FILE * fp, * inptr, * inptr2;
char buffer [81];
int i, count=1;
int count2=1;
int x;
fp = fopen ( FILENAME, "r" );
inptr = fopen ( "east.dat", "w");
inptr2 = fopen ( "west.dat", "w");
x = 1;
while ( fgets( buffer, sizeof buffer, fp ) != NULL )
{
fputs( buffer, stdout );
for ( i = 0; i < sizeof buffer; i++)
{
buffer[i] = toupper(buffer[i]);
}
if (x==1)
{
x = 0;
fprintf(inptr, "Roster#%i - %s", count++, buffer);
}
else
{
x=1;
fprintf(inptr2, "Roster#%i - %s", count2++, buffer);}
}
fgets(buffer, 81, fp);
fclose(fp);
fclose(inptr);
fclose(inptr2);
}