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);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.