Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:16:57+00:00 2026-06-06T07:16:57+00:00

The program i am working on creates a file (about.txt) which includes a highscore

  • 0

The program i am working on creates a file (about.txt) which includes a highscore section.

On line 12 of the .txt is…

Plain Text (With no highscore):

- with <0>

C:

fprintf(about,"-%s with <%ld>",highname,highscore);

I need to read the score from the file and test to see if it is larger than the current highscore before writing the new one.

i need…

if(score > highscore)
  highscore=score;

The only problem is how do i get highscore from the file.

I did some research myself and im sure that this is much easier than i am making it but when i looked around i couldnt find any way to do this.

Thank you.
/////////////////////////////////EDIT////////////////////////
Creating the file:

 FILE *about;
    fpos_t position_name;
    fpos_t position_score;
    ...
    fprintf(about,"\n\nHIGHSCORE:\n\n");
    fprintf(about,"-");
    fgetpos(about,&position_name);
    fprintf(about,"%s",highname);
    fprintf(about,"with");
    fgetpos(about,&position_score);
    fprintf(about,"%ld",highscore);
    fclose(about);
    ...

Getting Scores:

      FILE *about;
      about = fopen("about.txt","r");

      fseek(about,position_name,SEEK_SET);
      fscanf(about,"%s",highname);
      fseek(about,position_score,SEEK_SET);
      fscanf(about,"%ld",highscore);
      fclose(about);

Changing the variables (note.. highscore/highname are global variables)

if(score >= highscore) //alter highscore
    {
      highscore = score;
      highname = name;
      puts("NEW HIGHSCORE!!!\n");
    }

I get the error:

error: incompatible types when assigning to type 'char[3]' from type 'char'

On this line:

highname = name;

Name/score/highname/highscore declared here(in a header file):

char name[3];
char highname[3];
long score;
long highscore;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:17:00+00:00Added an answer on June 6, 2026 at 7:17 am

    You can use fscanf‘s little known but very powerful regex feature, together with its ability to skip entries based on regular expressions:

    Open the file, and skip the first 11 lines in a loop. Then read the score, like this:

    FILE *f = fopen("about.txt","r");
    int i, score;
    char buf[1024];
    for (i = 0 ; i != 11 ; i++) {
        fgets(buf, 1024, f);
    }
    fscanf(f, "%*[^<]%*[<]%d", &score);
    printf("%d\n", score);
    

    This will skip everything in the file up to the opening < bracket, then skip the bracket itself, and read an integer entry. Note that %* in the format string designates an entry to be skipped by fscanf. Here is a snippet at ideone.

    EDIT — In response to the additional question from your edit: you cannot assign arrays like that, you should use memcpy instead:

    memcpy(highname, name, 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program that creates thumbnails of JPEG images on the fly.
I'm currently working on a C# program that creates a List, of object Task,
I am working on a project which basically involves parsing and storing information about
I've created a class to mimic a file structure for a program (a text-based
Working on a school project, the program is supposed to read from a text
I am working on a program that encodes a file based on a supplied
I'm trying to get a simple winsock program working, so I create my socket
I am working on a program and part of it requires me to create
Background: I am writing a C++ program working with large amounts of geodata, and
how can i make java program working with multiple languages (frensh, english , arabic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.