Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ program, infinite loop on input
    text
    copied!<p>Hello i compile this program to an executable called picodb and try to run it through a shell bash script at linux. </p> <pre><code>int main(int argc, char** argv) { Debbuger DB(argc,argv); char command[12]; int len; bool valid; while(1) { valid=true; cin.clear(); cin&gt;&gt;command; len=strlen(command); if(command[0]=='t') { if(strcmp(command,"trace")==0 || len==1) { cin&gt;&gt;command; valid=DB.Trace(command); } else valid=false; } else if(command[0]=='r') { if(strcmp(command,"redirect")==0 || len==1) { char stream[6],file[15]; cin&gt;&gt;stream; cin&gt;&gt;file; valid=DB.Redirect(stream,file); } else valid=false; } else if(command[0]=='b') { if(strcmp(command,"blocking-mode")==0 || len==1) { cin&gt;&gt;command; valid=DB.Blocking_mode(command); } else valid=false; } else if(command[0]=='l') { if(strcmp(command,"limit-trace")==0 || len==1) { int n; cin&gt;&gt;n; valid=DB.Limit_Trace(n); } else valid=false; } else if(command[0]=='g') { if(strcmp(command,"go")==0 || len==1) { DB.Go(argv[1]) ; } } else if(command[0]=='q') { if(strcmp(command,"quit")==0 || len==1) return 0; else valid=false; } else if(command[0]=='h') { if(strcmp(command,"help")==0 || len==1) DB.Help(); else valid=false; } else valid =false; if(valid==false) { cout&lt;&lt;"Invalid command"&lt;&lt;endl; } } } </code></pre> <p>The script is this:</p> <pre><code>#!/bin/bash ./picodb &lt;&lt; EOF t file_management r stdin input.txt EOF </code></pre> <p>but when i execute this script the program goes to an infinite loop where it gets the "t file_management" and never stops or change this input. I printed the string command and it always has the value " t file_management" the first argument. I can't figure what I am doing wrong. I tried running the program at terminal giving it the inputs by hand and works fine.</p> <p>Edit:To make it clearer this is supposed to be a user interface.It never gets out of loop until you type quit.The problem is that what is read throuth the bash repeats to infinite.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload