Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago