Link to home
Start Free TrialLog in
Avatar of superwick
superwick

asked on

inputting from txt file into an array

Hi I'm a total beginner to C and i'm just looking for some code that will take in data from a txt file (for ex: a list of numbers separated by spaces) and put them into an array

thanks...
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

there are lots of these examples at EE:
https://www.experts-exchange.com/questions/21722375/Parsing-CSV-File.html
https://www.experts-exchange.com/questions/21417831/Parse-a-CSV-File.html
https://www.experts-exchange.com/questions/20407343/How-to-read-a-cvs-file.html

there are different approaches to read and parse the file (the same if separated by comma or by spaces), have a look to all the discussions there.

Avatar of superwick
superwick

ASKER

All those pages just really confused me... sorry I'm a total beginner in C

If I have a txt file with contents :
2 5 7 8 10

how can i get those numbers into an array so for example array[0] is 2, array[1] is 5, array[2] is 7, etc?

Please, I would really appreciate some example code for this..
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial