Problem with argc

This is a discussion on Problem with argc within the C++ Programming forums, part of the General Programming Boards category; No the way to escape any of the special characters, which include (from memory) [, ], ;, <space>, >, <, ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,750
    No the way to escape any of the special characters, which include (from memory) [, ], ;, <space>, >, <, |, and & is to surround the argument that uses them in double quotes.

    TBH I have been trying to reproduce your problem, and I can't no matter what I do. So I have to suspect you're doing something extremely wrong.

    Compile main with the strictest definition possible:

    Code:
     int main ( const int argc, const char *const *argv )
    We shall see what happens. Maybe you modify these variables in the program.

  2. #17
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by whiteflags View Post
    No the way to escape any of the special characters, which include (from memory) [, ], ;, <space>, >, <, |, and & is to surround the argument that uses them in double quotes.
    ..which I did, but it still enters that if statement.
    TBH I have been trying to reproduce your problem, and I can't no matter what I do. So I have to suspect you're doing something extremely wrong.

    Compile main with the strictest definition possible:

    Code:
     int main ( const int argc, const char *const *argv )
    We shall see what happens. Maybe you modify these variables in the program.
    That's ridiculous. I certainly do not. I do not modify them in any way. I just retrieve the argv[] strings after the checks on argc have been made, and store them inside C++ strings.

    I'll a post a short version of my program...ahh, heck. No, I wont. I'll post the whole thing, so y'all can look over it. Its only one source file, and its not that long, and it'll save typing, and will ensure I didn't miss anything important.
    Last edited by Programmer_P; 02-21-2011 at 06:13 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  3. #18
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Ok, here is the file:

    ReplaceStrsInLines.cpp
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  4. #19
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Works fine for me as well, with or without the escaping, on Mac OS X.

    Code:
    /pp "/home/USERNAME/Documents/C_html4_elements.h" "[string;desc]" "[C_html_element;element]"
    Thank you for running ReplaceStrsInLines.
    This program was created for the purpose of reading a file,
    finding every line of the file which includes each search string
    passed to the program, and replacing the bits of text in those lines
    with the replace strings you pass to the program.
    
    Please press Enter to continue.
    
    Processing...please wait.
    argv[0] is:
    ./pp
    
    argv[1] is:
    /home/USERNAME/Documents/C_html4_elements.h
    
    argv[2] is:
    [string;desc]
    
    argv[3] is:
    [C_html_element;element]

  5. #20
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,750
    That's ridiculous. I certainly do not. I do not modify them in any way. I just retrieve the argv[] strings after the checks on argc have been made, and store them inside C++ strings.
    I'm really sorry if you were offended, but we are heading into ridiculous territory.

    Apart from things that I obviously don't have, so your program wouldn't open any files, I get this:

    Thank you for running ReplaceStrsInLines.
    This program was created for the purpose of reading a file,
    finding every line of the file which includes each search string
    passed to the program, and replacing the bits of text in those lines
    with the replace strings you pass to the program.

    Please press Enter to continue.

    Processing...please wait.
    argv[0] is:
    C:\Documents and Settings\Owner\My Documents\sandbox\bin\Debug\sandbox.exe

    argv[1] is:
    /home/USERNAME/Documents/C_html4_elements.h

    argv[2] is:
    [string;desc]

    argv[3] is:
    [C_html_element;element]

    input_filepath is: /home/USERNAME/Documents/C_html4_elements.h
    search_strs_str is: [string;desc]
    replace_strs_str is: [C_html_element;element]
    Error! The file you passed could not be opened.
    Please verify your filepath, and try again.

    Exiting out...

    Process returned 1 (0x1) execution time : 2.422 s
    Press any key to continue.
    Can't reproduce the problem. What else can you tell us?

    Would you be willing to use a workaround? Put these arguments into a file, and work with the file instead. You could make the filepath the argument. That way we can get away from console parsing or whatever is broken here.
    Last edited by whiteflags; 02-21-2011 at 06:48 PM. Reason: Accidentally used the wrong arguments.

  6. #21
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by rags_to_riches View Post
    Works fine for me as well, with or without the escaping, on Mac OS X.

    Code:
    /pp "/home/USERNAME/Documents/C_html4_elements.h" "[string;desc]" "[C_html_element;element]"
    Thank you for running ReplaceStrsInLines.
    This program was created for the purpose of reading a file,
    finding every line of the file which includes each search string
    passed to the program, and replacing the bits of text in those lines
    with the replace strings you pass to the program.
    
    Please press Enter to continue.
    
    Processing...please wait.
    argv[0] is:
    ./pp
    
    argv[1] is:
    /home/USERNAME/Documents/C_html4_elements.h
    
    argv[2] is:
    [string;desc]
    
    argv[3] is:
    [C_html_element;element]
    Ok, well I'm sure the shell in Mac OS X is a lot different than the shell in Ubuntu 8.10.
    That's probably why you can't reproduce the problem that I'm getting.
    Quote Originally Posted by whiteflags View Post
    I'm really sorry if you were offended, but we are heading into ridiculous territory.
    No worries. I understand that you couldn't have known that I didn't modify those variables. Its just that I'm getting a little frustrated with this problem now, as I'm making little headway, and have been working on it for several hours now, and it makes no sense at all.
    Apart from things that I obviously don't have, so your program wouldn't open any files, I get this:



    Can't reproduce the problem. What else can you tell us?

    Would you be willing to use a workaround? Put these arguments into a file, and work with the file instead. You could make the filepath the argument. That way we can get away from console parsing or whatever is broken here.
    What OS are you using?
    Since its probably a shell problem, the probable reason neither of you can reproduce my problem is the fact that both of you are using a different shell than I am.

    I may put the arguments in a file, but it seems like a poor way of doing things, and inconveniences the user.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  7. #22
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,750
    What OS are you using?
    Since its probably a shell problem, the probable reason neither of you can reproduce my problem is the fact that both of you are using a different shell than I am.
    Right! Well, I'm going to mentally kick myself for not providing that earlier.

    I use Windows XP SP3's command prompt.

  8. #23
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Ok...this is interesting.
    When I run my program through the Ubuntu Gnome-Terminal with the same arguments, it works fine. It only produces the problem I posted about when I run it through xterm by pressing the Run button in the Code::Blocks IDE.

    So it must be a bug in xterm. I already posted about the issue on the Ubuntu forums.
    Hopefully the guys over there will take care of it.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    2,879
    I was able to duplicate your results. The semicolon seems to be a special character for the the xterm bash shell in Linux. If you change the semicolon to a comma it seems to work ok.

    Jim

  10. #25
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by jimblumberg View Post
    I was able to duplicate your results. The semicolon seems to be a special character for the the xterm bash shell in Linux. If you change the semicolon to a comma it seems to work ok.

    Jim
    Well, I had it to use commas originally, but then I needed to change a line which had a comma as part of the search string, so I decided to change the commas to semicolons instead. So now you want me to change it back??
    I decided a semicolon is more useful, as you would most likely not want to replace a semicolon, as that is the terminating character for nearly all programming statement lines in most languages.
    And anyway, even if it is a special character in xterm, it seems like to me that wrapping the argument with double quotes should make it ignore it, and treat it as part of the argument. Another thing, someone at the Ubuntu forums just suggested that I should replace all " characters with ' characters instead, but I just tried that, and still the same problem, so I guess the guy didn't know what he was talking about.

    EDIT: Ok, someone else just posted, and suggested that the problem is not xterm but is the cb_console_runner. So I guess I'm off now to go harass the Code::Blocks developers about this issue...
    Last edited by Programmer_P; 02-21-2011 at 08:13 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  11. #26
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by whiteflags View Post
    I should probably tackle this in parts.

    If the user is yourself: why are you uncomfortable with files? Programmers write files of all kinds every day. It's not "poor" unless your text editor is just awful.
    The user is myself, but its not about comfortableness. Its about speed.
    I dislike the thought of having to type out a different file first each time I want to run ReplaceStrsInLines, which seeing as I'm using it on my other programming projects, which I'm working on in almost daily basis, would be often.
    Instead, I want to be able to just run the program, and worry about what I have to pass to it as I'm typing the command in the console.

    I already found that thread you linked to, btw, and subscribed to it. Interesting behavior of Notepad, I might add. I knew about the line-wrap problem already, but the other things mentioned were new to me.

    If the user is anyone else: why would they be comfortable with command line arguments? I don't know an average joe who wants to run utilities this way; perhaps they do when there is a problem to fix.

    That's just my observation of human nature.
    Who knows...MY observations of people tell me that there is another level of person between "programmer" and "average joe", and that is the type of person who doesn't program, but likes using CLI-based programs over GUI. These type of people are often semi-geeks who can't be bothered to learn a programming language, but are interested in the command line nonetheless. Such people can be found on the Ubuntu forums nearly every day, just as a small example.
    And while you do that, Mr. Steel Balls, you need an interim solution.
    Really? Are you sure about that?
    I don't know...I kind of was thinking along the lines of pointing out the problem, and letting the developers of the software find the solution, since they are after all, the ones who are responsible for the problem I'm experiencing.

    EDIT: Or maybe I misunderstood what you meant...if you meant that I need a solution to use while I'm trying to get the other resolved, I've already got one: just run the program through the Gnome-Terminal, and forget about running it through Code::Blocks for now.
    Last edited by Programmer_P; 02-21-2011 at 09:33 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  12. #27
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,750
    Really? Are you sure about that?
    Well that whole post is probably not one of my brighter moments, but nothing precludes you from keeping this version which produces the problem and working around it for the meantime.

  13. #28
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Well, someone at the Code::Blocks forums gave me a workaround:

    Just surround the arguments with doublequotes, and surround the doublequotes with single quotes, which works. So now I am able to run the program through Code::Blocks, and pass the same arguments that broke it with only doublequotes.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. problem in calling DLL
    By bhagwat_maimt in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 10:43 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21