[A89] Re: Another Stupid String Question


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

[A89] Re: Another Stupid String Question




Did my message get to the list?  This code works perfectly, and is shorter (I would think that the
functions used are well optimized):
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();
}


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



References: