Question
How to read a text file into a struct (C programming)? I have a text file with a list of first and last names, such
How to read a text file into a struct (C programming)?
I have a text file with a list of first and last names, such as:
Jack Sparrow
Bilbo Baggins
Ramona Flowers
etc.
I also have a struct of arrays defined:
typedef struct {
char firstname [100];
char lastname [100];
} names;
I need to prompt the user to enter the file name (names.txt), which will open the file and read each column in the text file into the 2 arrays above. How would I do that? I've tried mutiple things, but haven't gotten it to work. Also, the text file is just a list of names that I created and will be using so the user won't be entering any names, just the file name.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started