[A89] Re: Another Stupid String Question


[Prev][Next][Index][Thread]

[A89] Re: Another Stupid String Question




You could do a character by character manual copy thing, but this seems to work too:
void _main(void)
{
	char *string="main\\var";  //be sure to initialize it with the doulbe slash!
	int offset=strstr(string,"\\")-string;   //finds the difference between the slash and the start
of the string
	char *folder=alloca(offset);      //allocates that much for the folder
	char *name=alloca(strlen(string)-offset-1);    //allocates the length of the original minus the
slash and folder name for the varname
	strncpy(folder,string,offset);      //copies just the folder
	strcpy(name,string+offset+1);       //copies starting at the beginning of the var to the end
	ClrScr();
	printf("%s\\%s",folder,name);       //prints out the path
	ngetchx();
}

jeff

--- Brett1228@aol.com wrote:
> I have a string declared like this:
> 
> char *string;
> 
> This string will contain a pathName and variableName, such as 
> "main\testprog". I want to put the pathName in one string, and the 
> variableName in the other. I just can't figure this out! I've been trying to 
> use strncat and strncpy, but nothing I do works.
> 
> Can anyone come up with code to do this for me? Thanks a lot!

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



References: