Reading a text file and inserting numbers into array in C -


i'm starting learn c myself. i've been trying learn of other languages myself (such java, html, css). anyways have basic question regarding inserting text file of numbers int array.

this how i'm starting (let me know if i'm doing wrong).

  1. i created text file using linux command prompt: cat > input.txt

  2. i entered random numbers of choosing input.txt: 14 21 78 14

  3. i want load numbers input.txt somehow array made in arraytest.c file.

here array made:

main() { int num[100]; // array want insert numbers input.txt }  void readnumbers() { // function reads numbers /* not sure how start -- nice */ }  void displaynumbers() { // function displays numbers in output printf("your numbers are:\n", num[1], num[2], num[3], num[4]); // example 

and output display so:

your numbers are: 14 21 78 14 

i've been looking @ tutorials , can't seem it.

look @ documentation file opertions; fopen, fread, , fclose. these let code access contents of file.

once have read data, or part of reading, can individual numbers.

you can learn breaking task down smaller parts, example, pretend have read file string , work on part numbers out of that.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -