Jammanuser
February 22nd, 2011, 02:41 AM
Hello,
I just developed a small little program called "ReplaceStrsInLines" in C++.
The program name is self-explanatory. Basically, what my problem is, my program works, but when I use xterm to execute the program, passing to it the following arguments, it breaks (and that, I believe is the fault of xterm, the program which starts my program when I click Run in the Code::Blocks IDE):
xterm -T ReplaceStrsInLines -e /usr/bin/cb_console_runner /home/gorilla/Documents/Programming_Projects/ReplaceStrsInLines/bin/Debug/ReplaceStrsInLines /home/gorilla/Documents/C_html4_elements.h "[string;desc]" "[C_html_element;element]"
As you can see, I pass 4 arguments, however an if statement which checks to see if argc (the number of arguments) is less than 4 is entered, and thus the program terminates pre-maturely, due to the fact that I do not allow any number of arguments less than 4 (including the program name) to be passed.
Now, I figured out what the problem was. Adding the following for loop to the program, right before the if statement, revealed what it is doing:
for (int i = 0; argv[i] != NULL; ++i)
cout<< "argv[" << i << "] is:\n" << argv[i] << '\n' <<endl;
This outputted the following information before the if statement was entered:
argv[0] is:
/home/USERNAME/Documents/Programming_Projects/ReplaceStrsInLines/bin/Debug/ReplaceStrsInLines
argv[1] is:
/home/USERNAME/Documents/C_html4_elements.h
argv[2] is:
[string
The bolded statement is what I'm getting at (as well as what it did NOT output, i.e. the fourth argument, because it was NULL). It clearly shows that for some reason, the third argument ends at "string" without the quotes, when it SHOULD have ended at the first space after the trailing double-quotes character that follows the third argument, thus I put forth the theory that either this is a bug of the "xterm" program (which I understand is a Terminal emulator packaged with Ubuntu, along with Gnome-Terminal), or a "feature". ;) Also note that when I pass the same arguments that I wrote above to my program, when running it through Gnome-Terminal, it interprets the arguments correctly.
Anyone know anything about this issue?
Thanks in advance.
-Jam Man
I just developed a small little program called "ReplaceStrsInLines" in C++.
The program name is self-explanatory. Basically, what my problem is, my program works, but when I use xterm to execute the program, passing to it the following arguments, it breaks (and that, I believe is the fault of xterm, the program which starts my program when I click Run in the Code::Blocks IDE):
xterm -T ReplaceStrsInLines -e /usr/bin/cb_console_runner /home/gorilla/Documents/Programming_Projects/ReplaceStrsInLines/bin/Debug/ReplaceStrsInLines /home/gorilla/Documents/C_html4_elements.h "[string;desc]" "[C_html_element;element]"
As you can see, I pass 4 arguments, however an if statement which checks to see if argc (the number of arguments) is less than 4 is entered, and thus the program terminates pre-maturely, due to the fact that I do not allow any number of arguments less than 4 (including the program name) to be passed.
Now, I figured out what the problem was. Adding the following for loop to the program, right before the if statement, revealed what it is doing:
for (int i = 0; argv[i] != NULL; ++i)
cout<< "argv[" << i << "] is:\n" << argv[i] << '\n' <<endl;
This outputted the following information before the if statement was entered:
argv[0] is:
/home/USERNAME/Documents/Programming_Projects/ReplaceStrsInLines/bin/Debug/ReplaceStrsInLines
argv[1] is:
/home/USERNAME/Documents/C_html4_elements.h
argv[2] is:
[string
The bolded statement is what I'm getting at (as well as what it did NOT output, i.e. the fourth argument, because it was NULL). It clearly shows that for some reason, the third argument ends at "string" without the quotes, when it SHOULD have ended at the first space after the trailing double-quotes character that follows the third argument, thus I put forth the theory that either this is a bug of the "xterm" program (which I understand is a Terminal emulator packaged with Ubuntu, along with Gnome-Terminal), or a "feature". ;) Also note that when I pass the same arguments that I wrote above to my program, when running it through Gnome-Terminal, it interprets the arguments correctly.
Anyone know anything about this issue?
Thanks in advance.
-Jam Man