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

  • SEARCH
  • Home
  • 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 6926981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:20+00:00 2026-05-27T10:59:20+00:00

I’ve got a question concerning C programming.It is concerning binary files.In my code I(at

  • 0

I’ve got a question concerning C programming.It is concerning binary files.In my code I(at least imagined that I) made it read and write from a binary file,but it won’t do that for some reason.I’ve tried changing some things but I just don’t see the error anywhere.And it is just this minimal detail which is giving me a hard time,it is all that is left to make in this code before it is done and then I’m done with the program altogether,so it gets on my nerves a bit more than it would usually.Please point out what it is I haven’t done and what i should do to make it read from and write to binary files properly:

 #define MAX 4

//========================-STRUCTURE-=====================================================================

struct person{

char name[30];
char mail[30];
char tele[30];

};

struct person p[MAX];

//========================-MAIN FUNCT-===============================================================
int main()
{

bool continue=true,exists=false;
int answer,i;
char filnme[20];

FILE *fil;

printf("Would you like to open an already existing file?[y/n]: ");
scanf("%d",&answer);
if(answer=='y'||answer=='Y')
{
    finns=true;
}
else finns=false;

getchar();

printf("\n\nType the name of the file you will use: ");
scanf("%s",filnme);

if(exists)
{

    fil = fopen(filnme,"rb");

    for(i=0;i<MAX;i++)
    {
        while(feof(fil)==0)
            {
            fread(&p, MAX, 1, fil);
            printf("%s %s %s\n",p.name,p.mail,p.tele);
        }

    }

    fclose(fil);
}

else fil = fopen(filnme,"wb");

do
{

    system("cls");

    int choice;

    printf("What would you like to do?");
    printf("\n_______________\n");
    printf("1. Add another person to the list\n");
    printf("2. Print the entire list\n");
    printf("3. Remove information from the list\n");
    printf("4. Sort\n");
    printf("5. Change information\n");
    printf("6. Search\n");
    printf("7. Exit\n");
    printf("\nChoice: ");
    scanf("%d",&choice);
    printf("\n");

    system("cls");

    switch(choice)
    {

        case 1:

        addtolist();
        getch();
        break;

        case 2:
        write();
        getch();
        break;

        case 3:
        remove();
        getch();
        break;

        case 4:
        sort();
        getch();
        break;

        case 5:
        change();
        getch();
        break;

        case 6:
        search();
        getch();
        break;

        case 7:
        continue=false;
        break;

        default:
        printf("Not a valid choice!");
        getch();
        break;

    }

}while(continue);

for(i=1;i<=MAX;i++)
{

        fwrite(&p, MAX, 1, fil);

}

fclose(fil);

system("cls");

}

Nevermind the declaration of functions or such,I’ve got that covered,just the binary file handling I put into the main.

Thanks in advance!

  • 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-05-27T10:59:21+00:00Added an answer on May 27, 2026 at 10:59 am

    You are not using fread and fwrite correctly.

    fread(&p, MAX, 1, fil);
    

    should be:

    fread(&p[i], sizeof(person), 1, fil);
    

    Similarly for the fwrite call.

    An alternative to calling fread and fwrite in a loop is to read/write the entire array in one go, like so:

    fread(&p, sizeof(person), MAX, fil);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.