Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

question: using function and taking references of two parameters to find out the highest score and the name from a txt file dont know why

question: using function and taking references of two parameters to find out the highest score and the name from a txt file

dont know why it turned out like this, seems like it's functioning

please find out where this program went wrong, thanks!!

image text in transcribed

#define _CRT_SECURE_NO_DEPRECATE

#include

#include

void getHighScore(char *name, int *score );

int main()

{

char name[20];

int score = 0;

getHighScore(name, &score);

printf("%s %d ", name, score);

system("pause"); // prevent the cmd close itself after the program has finished

return 0;

}

void getHighScore(char *name, int *score)

{

FILE * fpointer;

fpointer = fopen("scores.txt", "r"); // opens the txt file inorder to read the info, "r" stands for read

char thisLine[150]; //use to store content from the txt every single line

char names[50];

int scores = 0;

int current_score = 0;

int i = 1;

while (!feof(fpointer)) //run to the end, feof stands for file end of file

{

if (i % 2 == 0)

{

fgets(thisLine,150, fpointer);

current_score = atoi(thisLine);

}

else

{

fgets(names, 150, fpointer); /ames are used to store names from the txt

}

if (current_score > scores)

{

scores = current_score;

for (int k = 0; names[k] != '\0'; ++k)

{

name[k] = names[k];

}

}

i++;

}

*score = scores;

fclose(fpointer);

}image text in transcribed

#define CRT SECURE NO DEPRECATE 2 E#include #include 5 void getHighScore(char name, int *score ); 7 Eint main() char name [20] int score; getHighScore (name, &score); printf("%s %d ", name, score); system("pause")// prevent the cmd close itself after the program has finished return e clc H-L 12 13 14 15 ress any key to continu 17 18 19 2e 21 Evoid getHighScore(char "name, int *score) FILE fpointer; fpointer fopen("scores"txt", "r"); // opens the txt file inorder to read the info, "r" stands for read char thisLine[15e]; //use to store content from the txt every single line char names [50] int scores int current_scoree; int i = 1; 23 24 25 26 27 28 29 30 31 32 E while (Ifeof (fpointer)) //run to the end, feof stands for file end of file fgets (thisLine,150, fpointer); current-score = atoi (thsLine); 34 else

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

Recognize and discuss the causes of culture shock

Answered: 1 week ago

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago