none
how to check end of char* pointer array? RRS feed

  • Question

  • here am not able to get out the while loop.... is my condition in while loop valid for char pointer array? and also how to store the data in char* array to string or CString.


      char* param1 = new char[strlen (GetCommandLine ()) + 1];
     back: while(param1!='\0')   // maybe error here
            {
                if(*param1=='\ ')
                {
                    count1++;
                }         
                if(count1==2)
                {
                    //param2=param1;
                    goto back;
                }
                  param1++;
            }
    Regards,
    Thursday, April 5, 2007 10:08 AM

Answers

  • The condition in while is not ok. I think you mean:

    Code Snippet

    while(*param1 != '\0')

     

    Also, can you explain a little bit what are you trying to do? Why are you junping back to the while with a goto? That's so weird.

    Thursday, April 5, 2007 10:17 AM

All replies

  • The condition in while is not ok. I think you mean:

    Code Snippet

    while(*param1 != '\0')

     

    Also, can you explain a little bit what are you trying to do? Why are you junping back to the while with a goto? That's so weird.

    Thursday, April 5, 2007 10:17 AM
  • i need to scan the command line arguments which would be in the form

     pgm.exe 12212 "this would be the argument in sentence" then write this this two arguments seperatly in excel sheet by storing this arguments seperatly.
    Thursday, April 5, 2007 10:26 AM
  • and any idea to store char* pointer arrray in to string?
    Thursday, April 5, 2007 10:36 AM
  •  Ajax24 wrote:
    and any idea to store char* pointer arrray in to string?


    Code Snippet
    char* myCharArray = "sometext";
    std::string myString(myCharArray);

     


    Thursday, April 5, 2007 10:51 AM
    Moderator
  •  Ajax24 wrote:
    i need to scan the command line arguments which would be in the form

     pgm.exe 12212 "this would be the argument in sentence" then write this this two arguments seperatly in excel sheet by storing this arguments seperatly.

    You talk about CString, which tells me you are using MFC. In this case why don't you simply use CCommandLineInfo class. Derive it, override ParseParam() and it will be passed with each command option at a time. Take a look in MSDN for more.

    Thursday, April 5, 2007 12:15 PM
  •  einaros wrote:
     Ajax24 wrote:
    and any idea to store char* pointer arrray in to string?


    Code Snippet
    char* myCharArray = "sometext";
    std::string myString(myCharArray);

     


     

    const char* myCharArray = "sometext"; would be slightly better

    Thursday, April 5, 2007 2:12 PM
    Moderator
  • Alternatively, you could access the __argc and __argv/__wargv global variables.
    Thursday, April 5, 2007 2:40 PM
    Moderator
  • i need to scan the command line arguments which would be in the form

     pgm.exe 12212 "this would be the argument in sentence" then write this this two arguments seperatly in excel sheet by storing this arguments seperatly.

    #include <iostream> int main (int argc, char *argv[]) { // prints 'param1, param2' to stdout

    if (argc == 3) std::cout << argv[1] << ", " << argv[2] << "\n"; return 0; }



    • Edited by Steelyglow Friday, September 13, 2019 10:20 AM
    Friday, September 13, 2019 10:16 AM
  • @Steelyglow -

    Just in case you hadn't noticed, the post to which you replied is more than
    twelve (12) years old. A little late to be of much help to the OP, I expect.

    - Wayne

    Saturday, September 14, 2019 12:00 AM