2) ao points) Assuming there is an offline game, once players finish the game, t
ID: 3578000 • Letter: 2
Question
2) ao points) Assuming there is an offline game, once players finish the game, the final score would be stored in a score file. Now we have multiple players playing that game. Each player needs to play that game in two computers "Alpha" and "Beta". So there are two score files generated separately in two computers our goal is to check those two files and join the score for each player together to create a final file "score final.txt" for future statics. suppose the score file in computer "Alpha" has been renamed as "score alp in computer "Beta" the score file has been renamed as "score beta In score a colon separates the player's name and score. example of "score alpha txt" One "score beta final score fle "score final txt"are like below: score alpha.txt Allen 12 Bob:25 Carl 36 Kevin: 121 Tomy: 99 Jack 108Explanation / Answer
Solution:
#This C Program joins lines of two given files and stores them in a new file.
The source code for the C Program to join lines of two given files and store them in a new file.
/* Source Code */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
/* Function Prototype for Myjoins*/
int Myjoin(FILE *, FILE *, FILE *);
char c;
int flag;
void main(int argc, char *argv[])
{
clrscr();
FILE *file 1, *file 2, *tar;
file 1 = fopen (argv[1], "r");
if (filel = = NULL)
{
Perror("Error!");
}
}
file2 = Fopen(argv[2], "r");
if (file2 = = NULL)
{
perror("Error!");
}
tar = fopen(argv[3], "a");
if (tar = = NULL)
{
perror("Error!");
}
joinfiles (file 1, file 2, tar); /* Calling Function */
if (flag = = 1)
{
printf("The files have been successfully joined ");
}
}
/* Code join the two given files line by line into a new file */
int joinfiles (FILE *file 1, FILE *file2, FILE *tar)
{
while (( fgetc (file 1) != EOF ) | | (fgetc (File 2) ! = E0F))
{
fseek (file l, -1, 1);
while ((c = fgetc(file 1)) != ' ')
{
if (c = = EOF)
{
break;
}
else
{
fputc (c, tar);
}
}
while ((c = fgetc (file 2)) != ' ')
{
if (c = = EOF)
{
break;
}
else
{
fputc (c, tar);
}
}
fputc (" ", tar);
}
}
fclose(file 1);
fclose(file 2);
fclose(tar);
return flag = 1;
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.