How can i turn a list of numbers separated by a newline into an array?

So I have a list of numbers in a .txt file where each number is on a new line, like this:

1
2
3
4
5
6
1
2
3
4
5
etc.


I want to turn that list of numbers into an array. How can I do that? Thanks in advance! :)
Hello CP1 B1 GH1 432,

It really does not matter if the numbers are on a separate line or just separated by a space. That part is minor.

Start with some code that creates a file stream and opens the file.

Then you could use a loop to read the file.

Your choice then would be either to read into a variable and put the variable into the array or read directly into the array.

Work in small parts or steps. Compile often and check for errors, so that you only have a few errors to correct. Test as often as you can to see what is working.


#include <Necessary header files>

int main()
{
    define variables

    define file stream. Can open file here.

    Open file if you have not done so yet.

    Read the first number.

    When that works create a loop to read the entire file.

    Once this works you can continue with the rest of the program.
}



Andy

Edit:

When you have that part working or not post you code.
Last edited on
Topic archived. No new replies allowed.