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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:55:15+00:00 2026-05-20T09:55:15+00:00

Hey all, I’m writing a C program, and I want to have an array

  • 0

Hey all, I’m writing a C program, and I want to have an array of structs malloc’d up and filled with data from a file. Here’s my typedef for the struct:

typedef struct {
   char name[5];
   int age;
} person;

And then in my main function I do this:

  person *A ;
  int  i ;
  FILE * fin;

  fin = fopen( "people", "r" );

  A = ( person * ) malloc( sizeof(person) * 10 );
  if ( A == NULL ) { printf( "Error mallocing \n" ) ; return -1 ; }

  for( i = 0; i < 10; i++ ) {

    fscanf( fin, "%s %d", name->A[i], age->A[i] );

  }

Now unfortunately when I try to compile I get the error that name and age are undeclared in main. I’ve never tried using fscanf to make structs before, but I’m at a bit of a loss here. Thanks in advance to anyone who knows anything!

  • 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-20T09:55:15+00:00Added an answer on May 20, 2026 at 9:55 am

    You just accidentally got your syntax backwards (that and the fact that indexing the pointer returns an actual struct, not a pointer to it so the pointer to member operator -> is not needed): A[i].name and &(A[i].age). Also checking the return value from fopen might be a good idea.

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

Sidebar

Related Questions

hey all.i'm newbie at this problem.i have this data in table result: item range_code
Hey all , I want to put a flash file in the bottom of
Hey all, I have something of an interesting requirement for my project. I need
Hey all - I have an app where I'm authenticating the user. They pass
Hey all. I have a server written in java using the ServerSocket and Socket
Hey all. I've downloaded and moved the Xerces (v3.1.1) source here: /usr/include/xerces and I
Hey all, weird question. My company has an application from another company that records
Hey all! Ive got timezone troubles. I have a time stamp of 2010-07-26 23:35:03
Hey all, I'm writing a little 3D engine for android to better learn the
hEY ALL i have a table that shows transactions and their status. How can

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.