Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT!!! String manipulation question 1

Status
Not open for further replies.

luvcal

Programmer
Aug 10, 2001
54
US
I have a program that requires a string to have a null char in the middle of the string (i.e. "Keyword=value\0Keyword=value"). I am getting the value part of that string from the command line and am having a tough time constructing the string. I do the following:

strcpy(strParam,"Keyword1=");
strcat(strParam,argv[2]);

What I need to do is keep the NULL character at the end of that string, but add another "Keyword2=" + argv[3] and then add another \0 at the end of the whole thing. I think I should create a pointer to point to the address of the strParam[strlen+1] and then change the pointer, but I'm not sure of the syntax to do this. Any and all help will be appreciated...I'm sure this is simple, it's just been a long time since I worked in C.
 
This should work
----------
char * strparam = malloc(max sizeof Ur string)l
char *orig_strparam = strparam;

strcpy(strParam,"Keyword1=");
strcat(strParam,argv[2]);

strParam += (strlen(strParam) + 1);

strcpy(strParam,"Keyword2=");
strcat(strParam,argv[3]);
-----
But now you ahve to be carefull awhen U try to read from the string. You have to make sure you know how many NULL seperated strings are there in strParam,otherwise Ur program will dump core.

cheers
amit
crazy_indian@lycos.com

to bug is human to debug devine
 
Thanks for your help. I got it working 2 minutes before I got your post...I did something similar to what you did. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top