473,795 Members | 3,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help me to find out what is wrong with this code

180 New Member
Hello everybody,
This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query.

Here is the code which I have written.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. class myClass
  6. {
  7. public:
  8.     myClass(){}
  9.     friend std::istream& operator>>(std::istream& i, myClass& ct);
  10.     std::istream& extractor(std::istream& i);
  11. };
  12.  
  13. std::istream& myClass::extractor(std::istream& i)
  14. {
  15.     char line[256];
  16.     char keyword[64];
  17.     char origKeyword[64];
  18.     int  p;
  19.     char cp;
  20.     bool finished = false;
  21.     bool endct = false;    
  22.  
  23.     while( i && !finished )
  24.         {
  25.             if( (p = i.peek()) == ';' || p == '#' )
  26.             {
  27.             // read the comment line and discard it
  28.             i.getline( line, 255 );
  29.             continue;
  30.             }        
  31.             // check for eof or error
  32.             if( !i )
  33.                 continue;
  34.             while( i && isspace( p = i.peek() ) )
  35.             {
  36.             i.get(cp);
  37.             }
  38.             // check for error or eof
  39.             if( !i )
  40.                 continue;
  41.  
  42.             if( !endct )
  43.             {
  44.             // check for a digit, and if we don't get one it means we
  45.             // are done with tablecounting
  46.                 if( ( p = i.peek() ) != EOF && isdigit( p ) )
  47.                 {
  48.                     i.getline(line, sizeof(line));    
  49.                     continue;
  50.                 }
  51.                 else
  52.                 {
  53.                 // this is the end of the connection table proper
  54.                 endct = true;
  55.                 }
  56.             }
  57.  
  58.             if( ( p = i.peek() ) != EOF && isalpha( p ) )
  59.             {
  60.             // read the keyword, and deal with the input
  61.             i >> origKeyword;
  62.             // make a copy of the keyword, in case we need to put it back in the stream
  63.             strcpy( keyword, origKeyword );
  64.             // change to lower case
  65.             for( char *lp = keyword; *lp; ++lp )
  66.             {
  67.             *lp = tolower( *lp );
  68.             }
  69.             if( i )
  70.                 {
  71.                     if( !strncmp( keyword, "cis", 3 ) )
  72.                     {
  73.                         i.getline(line, sizeof(line));
  74.                     }
  75.                     else if( !strncmp( keyword, "trans", 5 ) )
  76.                     {
  77.                         i.getline(line, sizeof(line));
  78.                     }
  79.                     else if( !strncmp( keyword, "entgegen", 8 ) )
  80.                     {
  81.                         i.getline(line, sizeof(line));
  82.                     }
  83.                     else if( !strncmp( keyword, "zusammen", 8 ) )
  84.                     {
  85.                         i.getline(line, sizeof(line));
  86.                     }
  87.                     else if( !strncmp( keyword, "chiral", 6 ) )
  88.                     {
  89.                         i.getline(line, sizeof(line));
  90.                     }
  91.                     else if( !strncmp( keyword, "donttouch", 9 ) )
  92.                     {
  93.                         i.getline(line, sizeof(line));
  94.                     }
  95.                     else if( !strncmp( keyword, "startwith", 9 ) )
  96.                     {
  97.                         i.getline(line, sizeof(line));
  98.                     }
  99.                     else if( !strncmp( keyword, "keybond", 7 ) )
  100.                     {
  101.                         i.getline(line, sizeof(line));
  102.                     }
  103.                     else if( !strncmp( keyword, "planetrans", 10 ) )
  104.                     {
  105.                         i.getline(line, sizeof(line));
  106.                     }
  107.                     else if( !strncmp( keyword, "planecis", 8 ) )
  108.                     {
  109.                         i.getline(line, sizeof(line));
  110.                     }
  111.                     else if( !strncmp( keyword, "available", 9 ) )
  112.                     {
  113.                         i.getline(line, sizeof(line));
  114.                     }
  115.                     else
  116.                     {
  117.                         int len = strlen( origKeyword );
  118.                         for(char c = origKeyword[len-1]; len>0; --len)
  119.                         {
  120.                             c = origKeyword[len - 1];                            
  121.                             i.putback(c);
  122.                         }
  123.                         finished = true;
  124.                     }
  125.                 }//if i
  126.                 continue;
  127.             }
  128.  
  129.         if( EOF == i.peek() )
  130.             break;
  131.         }//while
  132.         return i;
  133. }
  134.  
  135. std::istream& operator>>(std::istream& i, myClass& ct)
  136. {
  137.     return ct.extractor( i );
  138. }
  139.  
  140. bool loadFile( std::istream &i )
  141. {
  142.     if(i)
  143.     {
  144.         int ii = 1;
  145.         char line[256];
  146.         int  p;
  147.         char cp;        
  148.         bool finished = false;
  149.         int  routesw = 2;        // routesw == 2 means the beginning of the file
  150.  
  151.         int  ctsw = 0;
  152.         int  infosw = 0;        
  153.         myClass* ct = NULL;
  154.  
  155.         while( i && !finished )
  156.             {
  157.                 if( (p = i.peek()) == ';' || p == '#' )
  158.                 {
  159.                 // read the comment line and discard it
  160.                 i.getline( line, sizeof() );
  161.                 continue;
  162.                 }
  163.  
  164.                 // check for eof or error
  165.                 if( !i )
  166.                     continue;
  167.  
  168.                 // If we haven't reached EOF, read the line, and parse.
  169.                 // Otherwise break the loop and finish.
  170.                 // The getline() function reads to the '\n' (or sizeof(line) - 1),
  171.                 // discards it, and appends a '\0' to the line.
  172.                 if( ( p = i.peek() ) != EOF )
  173.                 {
  174.                     i.getline( line, sizeof(line) );
  175.                     cout<<line<<endl;    
  176.                     if(ii == 4017)
  177.                     {
  178.                         cout<<ii<<endl;
  179.                     }
  180.                     ii++;
  181.                 }
  182.                 else
  183.                     break;
  184.                 if(i)
  185.                 {
  186.                     if( strstr(line,"CONNECTION TABLE") )
  187.                     {
  188.                         // The connection table starts on the next line,
  189.                         // and so we read it here. 
  190.                         // skip blank space at the beginning of the line
  191.                         while( i && isspace( p = i.peek() ) )
  192.                         {
  193.                             i.get(cp);
  194.                         }
  195.  
  196.                         // check for error or eof
  197.                         if( !i )
  198.                             continue;
  199.  
  200.                         // Check for a digit, meaning we are about to read a 
  201.                         // ConnectionTable.  Only allocate a new ct if we
  202.                         // are not at EOF and the next line begins with a digit.
  203.                         if( ( p = i.peek() ) != EOF && isdigit( p ) )
  204.                         {
  205.                             // Allocate a new connection table
  206.                             ct = new myClass;                                        
  207.                              i >> *ct;                                        
  208.                         }
  209.                         i.clear();
  210.                         // if we are at EOF then break
  211.                         if( EOF == i.peek() )
  212.                         {
  213.                             finished = true;
  214.                             break;
  215.                         }
  216.                     }                    
  217.                 } //if(i)
  218.                 // check whether we are at the end of the file
  219.             if( EOF == i.peek() )
  220.                 break;
  221.             }//while
  222.     return true;
  223.     }//if(i)
  224.     return false;
  225. }
  226.  
  227. int main(int argc, char* argv[])
  228. {
  229.     ifstream t("eugene.ct.syn", std::ios::in );
  230.     if(t)
  231.     {
  232.         t.seekg( 0, std::ios::beg );
  233.         if(loadFile( t ))
  234.         {
  235.             cout<<"File loaded completely"<<endl;
  236.         }
  237.         else
  238.             cout<<"File failed to load"<<endl;
  239.     }
  240.     t.close();
  241.  
  242.     return 0;
  243. }
Please dont get scared with the size of the code. I'm trying to read a file called "eugene.ct.syn" (given below as attached file). Now I want to read the entire file from starting till end. When I run this code on Visual C++ Editor, the program doesnt read the entire file, but I get the message "File loaded completely" written in main. Finally the program throws an exception at the end. I want to read the entire file. If you open the file with Microsoft word you can see some text contents in it. My target is to read the file till "THE PROGRAM HAS NOW FINISHED THE PROBLEM." (which you can see in the file(eugene.ct. syn) given below as attchment after you open it). I'm attaching the program too for you easiness.
Also I'm not able to guess why this program throws an exception.

Thankx in advance,
Rajeev
Attached Files
File Type: zip eugene.zip (19.9 KB, 111 views)
File Type: doc code.doc (29.0 KB, 323 views)
Aug 23 '06 #1
18 3131
vermarajeev
180 New Member
Hey sorry, there is some syntax error in that program.

Expand|Select|Wrap|Line Numbers
  1. bool loadFile( std::istream &i )
  2. {
  3.     if(i)
  4.     {
  5.         int ii = 1;
  6.         char line[256];
  7.         int  p;
  8.         char cp;        
  9.         bool finished = false;
  10.         int  routesw = 2;        // routesw == 2 means the beginning of the file
  11.  
  12.         int  ctsw = 0;
  13.         int  infosw = 0;        
  14.         myClass* ct = NULL;
  15.  
  16.         while( i && !finished )
  17.             {
  18.                 if( (p = i.peek()) == ';' || p == '#' )
  19.                 {
  20.                 // read the comment line and discard it
  21.                 i.getline( line, sizeof(line) );
  22.                 continue;
  23.                 }
There should be "sizeof(line) instead of sizeof()", Please correct that and run the program.
Aug 23 '06 #2
vermarajeev
180 New Member
Hi guys,
Aah! I think I have confused you guys. Or is that the code seems confusing.

Never mind. Let me clear. This is a simple program to read a text file. Firstly in main I call a method called "loadFile" which takes a stream as an argument.

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char* argv[])
  2. {
  3.     ifstream t("eugene.ct.syn", std::ios::in );
  4.     if(t)
  5.     {
  6.       t.seekg( 0, std::ios::beg );
  7.      if(loadFile( t ))
  8.       {
  9.           cout<<"File loaded completely"<<endl;
  10.       }
  11.      else
  12.          cout<<"File failed to load"<<endl;
  13.     }
  14.     t.close();
  15.     return 0;
  16. }
Then in method loadFile( t ), I just start reading the file till end. During this process, I check whether if I have read any "CONNECTION TABLE" which contains only digits in the file and if yes, then I create an object of myClass and allocate space for that, then I use overloaded operator ">>" defined in myClass to read that table(containin g digits). This operation is performed by the following code.

Expand|Select|Wrap|Line Numbers
  1. bool loadFile( std::istream &i )
  2. {
  3.     if(i)
  4.     {
  5.       char line[256];
  6.       int  p;
  7.       char cp;        
  8.       bool finished = false;    
  9.       int  ctsw = 0;
  10.       int  infosw = 0;        
  11.       myClass* ct = NULL;
  12.  
  13.       while( i && !finished )
  14.       {
  15.          if( (p = i.peek()) == ';' || p == '#' )
  16.          {
  17.             // read the comment line and discard it
  18.              i.getline( line, sizeof(line) );
  19.             continue;
  20.          }
  21.          // check for eof or error
  22.          if( !i )
  23.              continue;
  24.           // If we haven't reached EOF, read the line, and parse.
  25.           // Otherwise break the loop and finish.
  26.           // The getline() function reads to the '\n' (or sizeof(line) - 1),
  27.           // discards it, and appends a '\0' to the line.
  28.            if( ( p = i.peek() ) != EOF )
  29.             {
  30.                i.getline( line, sizeof(line) );
  31.                cout<<line<<endl;                    
  32.             }
  33.            else
  34.                break;
  35.             if(i)
  36.              {
  37.                  if( strstr(line,"CONNECTION TABLE") )
  38.                   {
  39.                     // The connection table starts on the next line,
  40.                     // and so we read it here. 
  41.                     // skip blank space at the beginning of the line
  42.                     while( i && isspace( p = i.peek() ) )
  43.                      {
  44.              i.get(cp);
  45.                      }    
  46.                      // check for error or eof
  47.                      if( !i )
  48.                        continue;
  49.                      // Check for a digit, meaning we are about to read a 
  50.                      // ConnectionTable.  Only allocate a new ct if we
  51.                      // are not at EOF and the next line begins with a digit.
  52.                      if( ( p = i.peek() ) != EOF && isdigit( p ) )
  53.                      {
  54.             // Allocate a new connection table
  55.            ct = new myClass;
  56.            i >> *ct;                
  57.                      }
  58.                      i.clear();
  59.                      // if we are at EOF then break
  60.           if( EOF == i.peek() )
  61.          {
  62.                    finished = true;
  63.                        break;
  64.          }
  65.                   }                
  66.              } //if(i)
  67.        // check whether we are at the end of the file
  68.        if( EOF == i.peek() )
  69.           break;
  70.       }//while
  71.     return true;
  72.    }//if(i)
  73.    return false;
  74. }
After this because of operator overloading "<<", this part of code is called

Expand|Select|Wrap|Line Numbers
  1. std::istream& operator>>(std::istream& i, myClass& ct)
  2. {
  3.     return ct.extractor( i );
  4. }
Finally in ct.extractor(i) , Firstly I'm reading all the connection table(all digits),
shown in this part of code defined in extractor(i)
Expand|Select|Wrap|Line Numbers
  1. if( !endct )
  2. {
  3.     // check for a digit, and if we don't get one it means we
  4.     // are done with tablecounting
  5.     if( ( p = i.peek() ) != EOF && isdigit( p ) )
  6.     {
  7.        i.getline(line, sizeof(line));    
  8.        continue;
  9.     }
  10.     else
  11.     {
  12.         // this is the end of the connection table proper
  13.        endct = true;
  14.     }
  15. }
Then, I check for various conditions, If I find the particular keyword I process that otherwise I put the keyword back to stream and return that stream. As in this part of code

Expand|Select|Wrap|Line Numbers
  1. if( ( p = i.peek() ) != EOF && isalpha( p ) )
  2. {
  3.    // read the keyword, and deal with the input
  4.    i>> origKeyword;
  5.    // make a copy of the keyword, in case we need to put it back in the stream
  6.    strcpy( keyword, origKeyword );
  7.    // change to lower case
  8.    for( char *lp = keyword; *lp; ++lp )
  9.    {
  10.       *lp = tolower( *lp );
  11.    }
  12.    if( i )
  13.    {
  14.    if( !strncmp( keyword, "cis", 3 ) )
  15.    {
  16.       i.getline(line, sizeof(line));
  17.    }
  18.    else if( !strncmp( keyword, "trans", 5 ) )
  19.    {
  20.       i.getline(line, sizeof(line));
  21.    }
  22.    else if( !strncmp( keyword, "entgegen", 8 ) )
  23.    {
  24.       i.getline(line, sizeof(line));
  25.    }
  26.    else if( !strncmp( keyword, "zusammen", 8 ) )
  27.    {
  28.       i.getline(line, sizeof(line));
  29.    }
  30.    else if( !strncmp( keyword, "chiral", 6 ) )
  31.    {
  32.       i.getline(line, sizeof(line));
  33.    }
  34.    else if( !strncmp( keyword, "donttouch", 9 ) )
  35.    {
  36.       i.getline(line, sizeof(line));
  37.    }
  38.    else if( !strncmp( keyword, "startwith", 9 ) )
  39.    {
  40.       i.getline(line, sizeof(line));
  41.    }
  42.    else if( !strncmp( keyword, "keybond", 7 ) )
  43.    {
  44.       i.getline(line, sizeof(line));
  45.    }
  46.    else if( !strncmp( keyword, "planetrans", 10 ) )
  47.    {
  48.       i.getline(line, sizeof(line));
  49.    }
  50.    else if( !strncmp( keyword, "planecis", 8 ) )
  51.    {
  52.       i.getline(line, sizeof(line));
  53.    } 
  54.    else if( !strncmp( keyword, "available", 9 ) )
  55.    {
  56.       i.getline(line, sizeof(line));
  57.    }
  58.    else
  59.    {
  60.       int len = strlen( origKeyword );
  61.       for(char c = origKeyword[len-1]; len>0; --len)
  62.       {
  63.          c = origKeyword[len - 1];                
  64.          i.putback(c);
  65.       }
  66.         finished = true;
  67.    }
  68.    }//if i
  69.    continue;
  70. }
Now the problem is since the file is too large, the program reads the contents of the file(eugene.ct. syn) but not completely. Finally the program throws an exception. I'm using Visual C++ 2003 to run this program. My target is to read complete file without any runtime error.

Please help me. I'm seeking your help at the earliest.

Thanks,
Rajeev
Aug 24 '06 #3
Ashaman0
7 New Member
Nothing obviously wrong has popped out at me yet, ill try downloading your attachments to look at your code a little closer.

What is the exception you are getting thou? And have you tried using a debuging utility to try and find out where the exception is being thrown and to see exactly what your code is actually doing?
Aug 24 '06 #4
Ashaman0
7 New Member
hmm. I just compiled and ran your code on linux. Seems to work fine, no exceptions, and i think it ran all the way through.


heres the end of the output. Is that right?
Expand|Select|Wrap|Line Numbers
  1. LIST OF EQUIVALENT ATOMS
  2. TOP[11] IS 11
  3. TOP[12] IS 11
  4. THERE IS ONE CHIRAL ATOM IN THE MOLECULE
  5. complexity = 9
  6. sumofcomplexity = 19
  7.  
  8. END OF DUMP OF m[2].
  9. }
  10. CT OF REACTANT
  11. THIS IS THE CONNECTION TABLE OF m[3].
  12. THE PRODUCT IS 2
  13. THE COREACTANT IS 0
  14. firstreactant 4
  15. PRODUCTATOMS 2 1 3 4 6 7 5 8 9 10 11 12
  16. FUNGP 4: 132 7: 115
  17.  
  18. REACTANTS WERE GENERATED 8293 TIMES
  19. 5793 DUPLICATE MOLECULES WERE ELIMINATED.
  20. 21 ROUTES WERE PROPOSED.
  21. THE PROGRAM HAS NOW FINISHED THE PROBLEM.
  22.  
  23. Fri Sep 26 15:45:30 EDT 2003
  24. File loaded completely
The only problem i had, was you were missing a variable on line 160.
it was
i.getline( line, sizeof( ) );
needed to be
i.getline( line, sizeof(line) );
that should have not compiled thou, not thrown an exception. Maybe a typo?
Aug 24 '06 #5
vermarajeev
180 New Member
Hi,
Thanx for your reply

That is what is more interesting about this code. Currently I'm using Microsoft Visual Studio .NET 2003 to run this program. When I run the same program on linux or Visual C++ Express Edition, it works fine.

Yeah, there was a syntax error which I have already mentioned in my previous post.
Try running the code on Microsoft Visual Studio .NET 2003 you will get an exception as "Run Time exception".

Can you suggest me why is this unusual scenario occuring?????

Thankx
Aug 25 '06 #6
Banfa
9,065 Recognized Expert Moderator Expert
Microsoft aren't any good at writing software :p

Try running lint/splint over your code. If any bits are particularly complex (multiple levels of pointers to structures to pointers etc) then try re-writing them using additional local variables to simplify the code.

Use the symbolic debugger to locate the exact error and line it is occuring on. It may give you a clue.
Aug 26 '06 #7
vermarajeev
180 New Member
Hi Banfa,
I was desperately waiting for your reply. Thanks for replying my post.

Could you please tell me what is lint/splint???, I have absolutely no idea about that.
Please explain me how I can correct that error.

Thanks
Aug 29 '06 #8
Banfa
9,065 Recognized Expert Moderator Expert
lint/splint/pclint are all versions (splint being free) of a utility that you can run on C/C++ code. This untility checks the code and reports Errors and Warnings much as a compiler would, however the errors and warnings it produces are normally much more detailed than most compilers and also contain information about errors that could occur at run time.

It is a useful to to ensure the rigerousness and robustness of your code.

If your code is working with 1 version of VC++ and not another version then one of the following errors has occured

1. You have used an extension that is only available in one of the versions (unlikely since it also works in Linux).

2. You have constructued the code in a way that causes a compiler bug to become apparent in the non-working version.

3. You have an error in the code that is not effecting the versions the code works on but is effecting the version that the code does not work on.

(sp)lint may help locate the problem if it is in category 3.

Using the symbolic debugger may help identify the location of the troublesome code, then visual examination may help fix the problem if it is in category 3 or if it is in category 2 then it may highlight a partiularly complex code syntax that could be simplified.

Good Luck, this is often a really hard type of bug to fix :-)
Aug 29 '06 #9
vermarajeev
180 New Member
Hi,
Glad to receive your reply :)

I just debuged the program and got to know that the stream which I'm using in my code, fails. As you can see the contents of the file "eugene", there are several strings like "Chiral", "available" , "CONNECTION TABLE" etc. As seen here for example

Expand|Select|Wrap|Line Numbers
  1. THIS IS STEP NUMBER 1
  2. CONNECTION TABLE
  3. 35  0  0    6  0  0  0  0  0            0            0  0  1
  4. 17  0  0    6  0  0  0  0  0            0            0  0  1
  5. 8   4  0    5  5  0  0  0  0            0            0  0  1
  6. 8   0  1    5  0  0  0  0  0            0            0  0  0
  7. 6   4  0    3  3  4  6  0  0        1.037       0.6625  0  1
  8. 6   0  1    1  2  5  0  0  0        1.381         0.85  1  1
  9. CHIRAL 6 C
  10. available Name:        BROMOCHLOROACETIC ACID
  11. available Supplier:        ALDRICH
  12. available Price:        61.95USD/5g 97%
  13.  
  14. CONNECTION TABLE
  15. 8   0  0    2  3  0  0  0  0            0            0  0  1
  16. 7   0  1    1  4  0  0  0  0            0            0  0  1
  17. 6   0  3    1  0  0  0  0  0            0            0  0  1
  18. 6   0  3    2  0  0  0  0  0            0            0  0  1
  19. available Name:        N,O-DIMETHYLHYDROXYLAMINE HYDROCHLORIDE
  20. available Supplier:        ALDRICH
  21. available Price:        173.70USD/100g 98%
Now suppose I'm at below shown position in the file
Expand|Select|Wrap|Line Numbers
  1. CHIRAL 6 C
  2. available Name:        BROMOCHLOROACETIC ACID
  3. available Supplier:        ALDRICH
  4. available Price:        61.95USD/5g 97%
So when I'm at this part of the program(as shown below)

Expand|Select|Wrap|Line Numbers
  1. if( ( p = i.peek() ) != EOF && isalpha( p ) )
  2. {
  3.    // read the keyword, and deal with the input
  4.    i>> origKeyword;
  5.    // make a copy of the keyword, in case we need to put it back in the stream
  6.    strcpy( keyword, origKeyword );
  7.    // change to lower case
  8.    for( char *lp = keyword; *lp; ++lp )
  9.    {
  10.       *lp = tolower( *lp );
  11.    }
  12.    if( i )
  13.    {
  14.    if( !strncmp( keyword, "cis", 3 ) )
  15.    {
  16.       i.getline(line, sizeof(line));
  17.    }
  18.    else if( !strncmp( keyword, "trans", 5 ) )
  19.    {
  20.       i.getline(line, sizeof(line));
  21.    }
  22.    else if( !strncmp( keyword, "entgegen", 8 ) )
  23.    {
  24.       i.getline(line, sizeof(line));
  25.    }
  26.    else if( !strncmp( keyword, "zusammen", 8 ) )
  27.    {
  28.       i.getline(line, sizeof(line));
  29.    }
  30.    else if( !strncmp( keyword, "chiral", 6 ) )
  31.    {
  32.       i.getline(line, sizeof(line));
  33.    }
  34.    else if( !strncmp( keyword, "donttouch", 9 ) )
  35.    {
  36.       i.getline(line, sizeof(line));
  37.    }
  38.    else if( !strncmp( keyword, "startwith", 9 ) )
  39.    {
  40.       i.getline(line, sizeof(line));
  41.    }
  42.    else if( !strncmp( keyword, "keybond", 7 ) )
  43.    {
  44.       i.getline(line, sizeof(line));
  45.    }
  46.    else if( !strncmp( keyword, "planetrans", 10 ) )
  47.    {
  48.       i.getline(line, sizeof(line));
  49.    }
  50.    else if( !strncmp( keyword, "planecis", 8 ) )
  51.    {
  52.       i.getline(line, sizeof(line));
  53.    } 
  54.    else if( !strncmp( keyword, "available", 9 ) )
  55.    {
  56.       i.getline(line, sizeof(line));
  57.    }
  58.    else
  59.    {
  60.       int len = strlen( origKeyword );
  61.       for(char c = origKeyword[len-1]; len>0; --len)
  62.       {
  63.          c = origKeyword[len - 1];                
  64.          i.putback(c);
  65.       }
  66.         finished = true;
  67.    }
  68.    }//if i
  69.    continue;
  70. }
Here in the code above the origKeyword is "CHIRAL" which I convert to lowercase and check the various conditions which satisfies this condition
Expand|Select|Wrap|Line Numbers
  1. else if( !strncmp( keyword, "chiral", 6 ) )
  2.    {
  3.       i.getline(line, sizeof(line));
  4.    }
Then the next three line after "CHIRAL" in the file is "available" which too satisfies this part of code
Expand|Select|Wrap|Line Numbers
  1. else if( !strncmp( keyword, "available", 9 ) )
  2.    {
  3.       i.getline(line, sizeof(line));
  4.    }
Finally when I read the next string which is "CONNECTION TABLE", else part in my code is called which is
Expand|Select|Wrap|Line Numbers
  1.  else
  2.    {
  3.       int len = strlen( origKeyword );
  4.       for(char c = origKeyword[len-1]; len>0; --len)
  5.       {
  6.          c = origKeyword[len - 1];                
  7.          i.putback(c);
  8.       }
  9.         finished = true;
  10.    }
here my len is 10, so char c = 'N' , hence 'N' is pushed back to stream. The stream now contains N ...(some data in the buffer).
Next c = 'O' is pushed stream contains ON...(some data in the buffer).
Next c = 'I' is pushed stream contains ION...(some data in the buffer).
Next c = 'T' is pushed stream contains TION...(some data in the buffer).
Next c = 'C' is pushed stream contains CTION...(some data in the buffer).
Next c = 'E' is pushed stream contains ECTION...(some data in the buffer).
Next c = 'N' is pushed stream contains NECTION...(some data in the buffer).

Now peroblem starts here,
When the next c = 'N' is pushed into the stream, stream still contains "NECTION...(som e data in the buffer)" instread of "NNECTION...(so me data in the buffer)". From here onwards if whatever is pushed onto the stream "i", It shows me "NECTION...(som e data in the buffer)". But the original sequence which I want is
Expand|Select|Wrap|Line Numbers
  1. "NNECTION...(some data in the buffer)"
  2. "ONNECTION...(some data in the buffer)"
  3. "CONNECTION...(some data in the buffer)"
Because the stream is not able to push back the character after N, it fails and throws exception.
Now, what can I do to solve this problem????. I just tried using
Expand|Select|Wrap|Line Numbers
  1. i.seekg(ios::cur, -len)
but this too fails, as the stream fails to return the correct position.
Please help me.
Aug 30 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2338
by: Kamil | last post by:
i dont know what i'm doing wrong i'm trying to get all the fields from a specific row by user name i'm using php and i got the connection string down and i made a query like this: $query = mysql_query("SELECT * FROM <DBname> WHERE name = $_POST"); the variable $_POST was passed to the php code from a previous html form i get the error: Unknown column '<username here>' in 'where clause'
1
1955
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the past 2 weeks now i give up and call for help. Please if anyone can gide me through i will be so grateful!! I have pasted my code below
9
4635
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is that if I type in any single character all the products that match the criteria should be displayed. So if I typed in an "a" I should get 3 returns (see below) Fields could look like this: product.options: bhw djhsa
27
2123
by: SK | last post by:
Hi I am trying to teach myself how to program in C. I am a physician hoping to be able to help restructure my office. Anyhow, I amhoping that the porblem I am having is simple to those much more experienced in programming. I am trying to use the concept of arrays to calculate the hours of my backoffice staff, however I am getting a ridiculous amount of error lines. If any one has time to help me that would be great. I am using the...
2
2062
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
13
4337
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error "operation is not allowed when object is open" so I take out the line of code: BookDetails.Connection1.Open and it comes up with the error "operation is not allowed when object
83
7879
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face some other ploblems which i can not correct.I would appreciated if someone take a look at my programm so as to help me.I tried many times to find out where my mistakes are but i didn't manage something. I have made some comments due to the programm...
16
2820
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
6
1646
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has encountered a problem and needs to close. We are sorry for the inconvience. If you were in the middle of something, the information you were working on might be lost
53
8421
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.