I'm starting to learn C by myself. I've been trying to learn as much of the other languages myself also (such as Java, HTML, CSS). Anyways I have a basic question regarding inserting a text file of numbers into an int array.
This is how I'm starting it (let me know if I'm doing anything wrong).
I created a text file using the Linux command prompt: cat > input.txt
I entered random numbers of my choosing into input.txt: 14 21 78 14
I want to load the numbers from input.txt somehow into my array that I made in my arrayTest.c file.
Here is the array that I made:
main() {
int num[100]; // My array that I want to insert numbers from input.txt into
}
void readNumbers() { // Function that reads the numbers
/* Not really sure how to start this -- help would be nice */
}
void displayNumbers() { // Function that displays the numbers in the output
printf("Your numbers are:\n", num[1], num[2], num[3], num[4]); // Just an example
And then the output would display as so:
Your numbers are: 14 21 78 14
I've been looking at tutorials and I just can't seem to get it.