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 7815031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:23:13+00:00 2026-06-02T05:23:13+00:00

I have an array being written to the file, but then I need a

  • 0

I have an array being written to the file, but then I need a way to print that same information out from the file when I call the function. The first part of the code is in the main function, and the second is a second function that prints out the values that are supposed to be from the file (fp).

fp = fopen("Grue.txt", "wb");
for(i = 0; i < 5; i++)
{
    char newLine[3] = {"\n"};
    char space[2] = {" "};
    fwrite(array[i].name, strlen(array[i].name), sizeof(char), fp);
    fwrite(space, strlen(space), sizeof(char), fp);
    fwrite(array[i].height, strlen(array[i].height), sizeof(char), fp);
    fwrite(space, strlen(space), sizeof(char), fp);
    fwrite(array[i].weight, strlen(array[i].weight), sizeof(char), fp);
    fwrite(space, strlen(space), sizeof(char), fp);
    fwrite(array[i].items, strlen(array[i].items), sizeof(char), fp);
    fwrite(newLine, strlen(newLine), sizeof(char), fp);
}
fclose(fp);
fp = fopen("Grue.txt", "rb");
PrintAGrue(fp);


void PrintAGrue(FILE *a)
{
 // create End of file character onto the array being saved,
int i;
char n;
char h;
char w;
char m;

for (i=0; i<5; i++)
{
     n = fread(a[i].name,  strlen(array[i].name, sizeof(char), a);
     h = fread(array[i].height,  strlen(array[i].height, sizeof(char), a);
     w = fread(array[i].weight,  strlen(array[i].weight, sizeof(char), a);
     m = fread(array[i].items,  strlen(array[i].items, sizeof(char), a);

     printf("This grue is called %s and is %s feet tall, and weighs %s pounds, and has eaten %s things.", n, h, w, m);
}

}

  • 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-02T05:23:14+00:00Added an answer on June 2, 2026 at 5:23 am

    In PrintAGrue, it looks like you’re using strlen() calls to decide how much data to read — but how
    can you know the size of the string before you’ve read it? (Also, the parentheses don’t look balanced…)

    Perhaps your file format should explicitly include a length field for each string — then you
    can do one fread to find the string size, and another to actually read the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView that is being populated from an NSMutable array that has
I have written this code but it will print these stack traces in the
I have an INI file that has been created by an AutoHotKey program written
I've written a PHP script that handles file downloads, determining which file is being
I have written the following script. It opens a file, reads each line from
I have pong balls that are being generated very consistently, but the rates change
I have some C++ code that is writing to a socket that is being
I have a several DBF files generated by a third party that I need
Context: I've just written a PHP file upload handler that saves any incoming file
I need to create a file that embeds an image as text within some

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.