Want help in string manipulation

Hi experts,
              I am writing a program which accepts command line arguments and process them. I am able to accept the string from the command line. The string is like

command -f "c:\temp.txt"  \servername:port\Getstatus

What I want is that is code helping to do the follwing things

> if a -f is noticed then take c:\temp.txt in a variable and pass it.
> Also the validation code for checking the correctioness of entry....(The command should be entered exactly in the format).
> Also I want servername:port seperately in another string....

Please help me in doing these things, urgent respondings is greatly appreciated

Thanks in advance

GM
google_manAsked:
Who is Participating?
 
sunnycoderConnect With a Mentor Commented:
>If I get the whole command

>"command -f "c:\temp.txt"  \servername:port\Getstatus"

>in a string and then what to process it with above procedures then how will i have to proceed

you have to proceed in a fashion similar to the one for command line args ... agrv[] would be replaced with the string name

>dummy = command -f "c:\temp.txt"  \servername:port\Getstatus

here I see a space between -f and ", which i had not considered in the previous post ... adjust code accordingly if that is the case

>if a -f is noticed then take c:\temp.txt in a variable and pass it.
previously we had

char * arg1;

if ( strncmp ( argv[1] , "-f", 2 ) == )
       arg1 = argv[1] + 3;

now it would be

if ( (arg1 = strstr ( dummy, "-f" ) ) != NULL )
         arg1 = arg1 + 4;

similar trivial modifications to other segments would get other cases working too ... read the man pages for strstr, strchr, strrchr, strcmp, strncmp, strlen
0
 
sunnycoderCommented:
> if a -f is noticed then take c:\temp.txt in a variable and pass it.
> Also the validation code for checking the correctioness of entry....(The command should be entered exactly in the format).
> Also I want servername:port seperately in another string....

>command -f "c:\temp.txt"  \servername:port\Getstatus


> if a -f is noticed then take c:\temp.txt in a variable and pass it.
char * arg1;

if ( strncmp ( argv[1] , "-f", 2 ) == )
        arg1 = argv[1] + 3;


> Also I want servername:port seperately in another string
char arg2[64];
char * temp;

temp = strrchr ( argv[2] , '\' );
strcpy ( arg2, argv[2]+1, temp - argv[2] );
arg2+(temp - argv[2] ) = '\0';

> Also the validation code for checking the correctioness of entry....(The command should be entered exactly in the format).
does that include the punctuation marks
0
 
sunnycoderCommented:
validation including punctuation
>command -f "c:\temp.txt"  \servername:port\Getstatus

if ( argc != 2 )
    /* wrong number of args */

if ( strncmp ( argv[1] , "-f\"", 3 ) != 0 )              ======== missed 0 last time
              /* ill formed argument 1*/

if ( argv[1] + (strlen (argv[1]) ) != '"' )
           /* ill formed argument 1*/

if ( *argv[2] != '\'   ||  strchr (argv[2],':' ) == NULL || strrchr (argv[2], '\' ) == argv[2] )
        /* ill formed argument2 */
0
 
google_manAuthor Commented:
Thanks very much for the code. Sorry for the late acceptance as I didn't got any mails regarding reply......

Also one more doubt...... If I get the whole command

"command -f "c:\temp.txt"  \servername:port\Getstatus"

in a string and then what to process it with above procedures then how will i have to proceed

eg:= Cstring dummy = command -f "c:\temp.txt"  \servername:port\Getstatus

Please solve this also. Iam giving you the points for the question
0
All Courses

From novice to tech pro — start learning today.