I have some code that seems to be working really well except when the ifsream reads in a line of text using getline. I am placing each character into a varible of char. I can see each character in the debug window except for the '}' character. It prints nothing. I also can see the '{' fine. Included is the version of the compiler I have, part of the code and the Complie Log. Thanks for any help that anyone can provide. I do believe it is a problem with the compiler or a lib file and not mhy code, but then again....
Version : 4.9.9.2
Sample of code:
int processFile()
ifstream in;
in.open("test.fls");
//getline() retuns false when no chars were read in.
//------------------------------------------------------------------------
while (in.getline(buffer, buff_Size))
{
//If we found a blank line, ignore it and continue
//------------------------------------------------------------------------
if (strlen(buffer) == 0)
{
continue;
}
}
Sorry about that. Let me explain a bit more. I am able to look (using the debug window) at the buffer string (using buffer[index]) and I an able to see all the characters in my file except the ones that are the { character. No matter where the { chracter is in the file. I have stepped through the code and all I see when it hits the buffer[index[ when the character is a { is blank. Then when the next character gets read in I get that character. For example, if the string is "This is a test }}} (((PPP]]]", I use the buffer[1] I get "T", if I use buffer[2] I get "i" and so on. If I use buffer[17] I get a blank. I keep getting a blank until I get to the "(((PPP]]]" and then I get those characters.
I am putting some of these characters in a link list and when I get to the { it places a blank in the list. It grabs all the other characters fine. So as anyone should see it seems that for some odd reason the getline function is not reading the { character correctly. Included is the entire function that I am using the get the data and I do not think that it is my code. I may try uninstalling Dev-C++ and do a clean re-install with the latest and greatest version. Any ideas anyone?
int processFile (node head)
/----------------------------------------------------------------------------
*
* Function: proccessFile
* Purpose: Opens a file to read items into a character value. It will take
* pass that to a function and place some of the characters into a linked list.
* Arguements: head - a pointer to the fist of the link list. Returns: 0 for success, 1 for failure
*/
{
ifstream in; //The input file.
int i = 0; //A loop counter
char buffer = new char[buff_Size]; //Used to hold a line of file text
struct node top = head;
in.open("stack.cpp");
//Ensure the files was open OK
//----------------------------------------------------------------------------
if(!(in))
{ //2
// Unable to open the file for reading.
cout <<"Error, could not open stack.cpp for reading." <<
endl;
return(1);
}
I have my program working properly. I had a typo in the code in another function. It is funny that you can not see that character in the debug window when reading it in from a file. Just one of those strange things I suppose. Thanks anyhew.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-10-06
>> I do believe it is a problem with the compiler or a lib file and not mhy code, but then again....
Always the assumption of last resort, and even if you believe that, it is a thought best kept to yourself because it is extremely unlikely to be true (as it was in this case), and you may just end up looking foolish. You should only conclude that the compiler is at fault when you have exactly identified the fault, can show how reproduce it, have referenced the appropriate ISO standard, and had your findings peer reviewed. To do that you really need to know your stuff.
With respect to what you are seeing in the debugger I am unclear as to what you observing, post short but complete (i.e. compilable) example. You may be misinterpreting what you are seeing, or the code may be at fault in a way that is not obvious; but frankly the debugger sucks so who knows?
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have some code that seems to be working really well except when the ifsream reads in a line of text using getline. I am placing each character into a varible of char. I can see each character in the debug window except for the '}' character. It prints nothing. I also can see the '{' fine. Included is the version of the compiler I have, part of the code and the Complie Log. Thanks for any help that anyone can provide. I do believe it is a problem with the compiler or a lib file and not mhy code, but then again....
Version : 4.9.9.2
Sample of code:
int processFile()
ifstream in;
in.open("test.fls");
//getline() retuns false when no chars were read in.
//------------------------------------------------------------------------
while (in.getline(buffer, buff_Size))
{
//If we found a blank line, ignore it and continue
//------------------------------------------------------------------------
if (strlen(buffer) == 0)
{
continue;
}
}
Compile Log
g++.exe "C:\Dev-Cpp\Proj3.cpp" -o "C:\Dev-Cpp\Proj3.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
Execution terminated
Compilation successful
I'm not sure you've posted enough code for anyone to see where your error might be.
Sorry about that. Let me explain a bit more. I am able to look (using the debug window) at the buffer string (using buffer[index]) and I an able to see all the characters in my file except the ones that are the { character. No matter where the { chracter is in the file. I have stepped through the code and all I see when it hits the buffer[index[ when the character is a { is blank. Then when the next character gets read in I get that character. For example, if the string is "This is a test }}} (((PPP]]]", I use the buffer[1] I get "T", if I use buffer[2] I get "i" and so on. If I use buffer[17] I get a blank. I keep getting a blank until I get to the "(((PPP]]]" and then I get those characters.
I am putting some of these characters in a link list and when I get to the { it places a blank in the list. It grabs all the other characters fine. So as anyone should see it seems that for some odd reason the getline function is not reading the { character correctly. Included is the entire function that I am using the get the data and I do not think that it is my code. I may try uninstalling Dev-C++ and do a clean re-install with the latest and greatest version. Any ideas anyone?
int processFile (node head)
/----------------------------------------------------------------------------
*
* Function: proccessFile
* Purpose: Opens a file to read items into a character value. It will take
* pass that to a function and place some of the characters into a linked list.
* Arguements: head - a pointer to the fist of the link list.
Returns: 0 for success, 1 for failure
*/
{
ifstream in; //The input file.
int i = 0; //A loop counter
char buffer = new char[buff_Size]; //Used to hold a line of file text
struct node top = head;
in.open("stack.cpp");
//Ensure the files was open OK
//----------------------------------------------------------------------------
if(!(in))
{ //2
// Unable to open the file for reading.
cout <<"Error, could not open stack.cpp for reading." <<
endl;
return(1);
}
return(0);
}
I have my program working properly. I had a typo in the code in another function. It is funny that you can not see that character in the debug window when reading it in from a file. Just one of those strange things I suppose. Thanks anyhew.
>> I do believe it is a problem with the compiler or a lib file and not mhy code, but then again....
Always the assumption of last resort, and even if you believe that, it is a thought best kept to yourself because it is extremely unlikely to be true (as it was in this case), and you may just end up looking foolish. You should only conclude that the compiler is at fault when you have exactly identified the fault, can show how reproduce it, have referenced the appropriate ISO standard, and had your findings peer reviewed. To do that you really need to know your stuff.
With respect to what you are seeing in the debugger I am unclear as to what you observing, post short but complete (i.e. compilable) example. You may be misinterpreting what you are seeing, or the code may be at fault in a way that is not obvious; but frankly the debugger sucks so who knows?
Clifford