Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Storing user input into array of structures (C programming)? I have a struct def

ID: 3815138 • Letter: S

Question

Storing user input into array of structures (C programming)?

I have a struct defined with 2 arrays and then I define it into an array of structures.

I'm prompting the user to enter a name and a number and I put it into name or balance. The name turns out and it stores correctly, but the number doesn't. When I print each member of the struct array, the out put is this:

Name: John

Balance: 435434 (or some other garbage number).

I need an array because it needs to store multiple as the number corresponds with a name and I can have up to 10 people with thier respective balances.

How do I fix this?

Explanation / Answer

#include<stdio.h>

#include<string.h>

int main()

{

typedef sturct

{

int n_adults;

int n_kinds;

char day [10];

}daydata;

daydata record [30];

FILE * filehandle;

char line [121];

char * item;

int recount =0;

int k;

filehandle=fopen("newstuff.txt");

while (fgets(lyne.120,filehandle))

{print("%s", lyne)}

item=strtok(lyne," ");

record[record]n_adults=atoi(item);

record[record]n_kids=atoi(item);

recount++;}

fclose(filehandle)

{

for(k=0,k<recount,k++)

printf("name",%s);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote