Answer the question
In order to leave comments, you need to log in
How to read a line from a file and write the numbers to an array?
I was given an input.txt file, which contains a line where numbers are indicated separated by a space (their number is unknown). You need to know their sum.
I don't understand the algorithm.
I'll offer my own
0. We read the data, but in order to count, it seems, you need to know the length of the string (Now a brilliant idea has come - find out the file size and divide by 2)
1. Take the si element of the array.
2. Check for a space
3. If there is a space, then go to the label num2arr. (In this label, we create a cycle with di iterations (i = from 0 to di-1). We pull out a digit character from the stack, convert the character into a digit (bx), perform such an operation - ax = (i * 10) + bx and so further to the end of the loop.Then we write ax to the array (one more variable is needed there))
4. If it's a number, then put it on the stack. We add some other variable, for example, di
But it seems to me that everything is confusing here and it can be easier. Tell me how.
Answer the question
In order to leave comments, you need to log in
I was given an input.txt file, which contains a line where numbers are indicated separated by a space (their number is unknown). You need to know their sum.
...
it seems to me that everything is confusing here and it can be easier. Tell me how.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question