![]() |
|
#1
|
|||
|
|||
Read from filesCPP / C++ / C Code:
Hello, i´ve done this code and i ve create in my c drive the input file, what i want to know is : how can i pic the numbers in the input file and then make the calculations and send to the output file. Thank you |
|
#2
|
|||
|
|||
Re: Read from filesWe need more information about what exactly you are trying to do, but a starter...
CPP / C++ / C Code:
This already reads the first number. By calling: CPP / C++ / C Code:
You're reading the next number and ignoring the first. By reading the number into n, you can do anything you want to do with them. Add it, subtract it, multiply it, divide it (though I don't suggest it with an int). It depends what you want to do your number read (n). When you're done with it, your loop automatically reads the next number. |
|
#3
|
|||
|
|||
Re: Read from filesCPP / C++ / C Code:
I want go to this .txt file and put the numbers that exit in it to a stack or array and then make calculations and send them to the output file. |
|
#4
|
|||
|
|||
Re: Read from filesQuote:
1. Read from input file: Your program does this, but, as dlp tried to point out, the program skips every other input value from the file. 2. Put the input numbers into an array: Declare an array and put each input value into the array. Start with array index = 0 and increment the index for every input value that you read. 3. Make calculations: OK. What array? What calculations? It's your program---do whatever you want. 4. Write results to output file. Your program writes to output file. I would suggest that for learning and debug purposes you might want to print results to the standard output also (cout <<) For example, here I simply read each value, perform a calculation, and put the result into an output file. If you want to store the values in an array, you can use count as the array index. CPP / C++ / C Code:
Input file "test.txt": Code:
Result of program run (console output): Code:
Output file "test.out" after the run: Code:
Regards, Dave |
|
#5
|
|||
|
|||
Re: Read from filesCPP / C++ / C Code:
Thank you davekw7x great explanation, but now i need to put this values into a a stack or into an array, how do i do this operation? |
|
#6
|
|||
|
|||
Re: Read from filesQuote:
As I said before: Quote:
Dave |
|
#7
|
|||
|
|||
Re: Read from filesI have read what you post, but i don´t know how to put those numbers into an array.
Thank you |
|
#8
|
|||
|
|||
Re: Read from filesQuote:
This is how you declare an array: CPP / C++ / C Code:
This is how you store something in the array (note that the value of count must be greater than or equal to zero and less than or equal to 99 for the above declaration) CPP / C++ / C Code:
Regards, Dave |
|
#9
|
|||
|
|||
Re: Read from filesCPP / C++ / C Code:
I made this way, but it´s not working. Is this you mean? |
|
#10
|
|||
|
|||
Re: Read from fileswhat about it isn't working?
|
Recent GIDBlog
2nd Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| hOW TO READ XLS FILES IN C/c++ | naveen | CPP / C++ Forum | 2 | 06-Jun-2005 13:47 |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
| C++, files | calculus87 | CPP / C++ Forum | 0 | 24-Sep-2003 10:01 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The