Code::Blocks Forums
User forums => Help => Topic started by: C0UG3R on January 25, 2015, 10:06:40 am
-
Sorry if explanation is bad, English is not my first language.
I'm needed to make code to read file and print code from file.
I'm new to coding but know the basics.
I've just included the code that written up to this point.
When program is run nothing shows up. Not even "Hi" at begin of code.
When I remove parts of code "Hi" shows up. It seem to cause problem when opening of file first starts in function.
If this is wrong place to post I apologize, anymore information needed can be provided.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void ReadData (int accts[], double balance [], int size);
void SortData (int accts[], double balance[]);
int ReadNumber ();
int Search (int userNum, int accts[], double balance []);
int main()
{
cout << "Hi";
//Declare variables
const int ARRAY_SIZE = 20;
int accts[ARRAY_SIZE];
double balance[ARRAY_SIZE];
int count;
int userNum;
//Call functions
ReadData (accts, balance, ARRAY_SIZE);
//Printing the Arrays
for(count = 0; count < 20; count++)
cout << accts[count] << " " << balance[count];
return 0;
}
void ReadData (int accts[], double balance [], int size)
{
ifstream infile; //input
int count;
//Opening the file
infile.open("demo.txt");
cout << "Opening file...\n";
if (!infile)
cout << "File open failure!\n";
//Reading the file
for(count = 0; count < size; count++)
{
infile >> accts[count];
infile >> balance[count];
}
//Closing the file
cout << "Closing file...\n";
infile.close();
return;
}
-
1) Please use code Tags, if you post code (the # symbol in the new post editor)
2)
When program is run nothing shows up. Not even "Hi" at begin of code.
When I remove parts of code "Hi" shows up. It seem to cause problem when opening of file first starts in function.
2.1) Does the program compile?
2.2) Does the compiler throws errors?
2.3) Does the console shows up?
2.4) Is the file "demo.txt" in the rigth folder (in the folder of the exe if you run it directly, in the folder of the .cbp file if you run it from within c::b)?
if 2.1 or 2.2: Give us the full rebuild log: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (read ALL and follow ALL steps)
if nothing from the upper points:
What code do you remove?
if not one of the upper parts, then it is probably a programming error, and so this forum is not the right place and this topic will probably get locked...
greetings
[Edit:] i have tested your program and on my pc it works without problems...
-
1) Please use code Tags, if you post code (the # symbol in the new post editor)
2)
When program is run nothing shows up. Not even "Hi" at begin of code.
When I remove parts of code "Hi" shows up. It seem to cause problem when opening of file first starts in function.
2.1) Does the program compile?
2.2) Does the compiler throws errors?
2.3) Does the console shows up?
2.4) Is the file "demo.txt" in the rigth folder (in the folder of the exe if you run it directly, in the folder of the .cbp file if you run it from within c::b)?
if 2.1 or 2.2: Give us the full rebuild log: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (read ALL and follow ALL steps)
if nothing from the upper points:
What code do you remove?
if not one of the upper parts, then it is probably a programming error, and so this forum is not the right place and this topic will probably get locked...
greetings
[Edit:] i have tested your program and on my pc it works without problems...
The code does compile. I have noticed no errors. The console does show up. And demo.txt is in the same folder as the program. I attempt to remove all of the code and one by one add to it and the part that is making the program print nothing is the "ifstream infile;".
-
2.4) Is the file "demo.txt" in the rigth folder (in the folder of the exe if you run it directly, in the folder of the .cbp file if you run it from within c::b)?
What os are you using.
NOTICE: as you pointed out, this is not a c::b error, but a general programming error/question. This forum is the wrong place to ask this questions. I can't guarantee that this topic won't get locked by an admin because it violates the rules
-
2.4) Is the file "demo.txt" in the rigth folder (in the folder of the exe if you run it directly, in the folder of the .cbp file if you run it from within c::b)?
What os are you using.
NOTICE: as you pointed out, this is not a c::b error, but a general programming error/question. This forum is the wrong place to ask this questions. I can't guarantee that this topic won't get locked by an admin because it violates the rules
Windows 7. What would be the correct forum that I should post to if this does get locked?
-
You need to learn how to post the full rebuild log; and ask the questions that are not valid on this site on another site.
That site should be one the supports either the programming Language, the Compiler, or the software Library being used.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Note: I only remember reading your last post; so, I have no idea if your issue is valid or not for this site.
For another site to look at I suggest this one http://cboard.cprogramming.com/ (http://cboard.cprogramming.com/)
Tim S.
-
When program is run nothing shows up. Not even "Hi" at begin of code.
When I remove parts of code "Hi" shows up. It seem to cause problem when opening of file first starts in function.
This happens because the std::cout is buffered and doesn't flush the buffers to the output device.
Read the iostream documentation to understand how to flush the buffers. Hint use std::endl;
-
Thank for all the replies. The code was for a friend but he die so I do not need anymore.
Bye.