String help! (getting ANSI C strings back out of ROM)

Guy Harris guy at rlgvax.UUCP
Wed Mar 20 15:26:02 AEST 1985


> By definition, in ANSI C (according to the latest Feb. draft) string
> constants are of type "const char[]".  The first horrified thought that
> comes to the mind of many UNIX programmers is "What do I do with all of my
> calls to mktemp() now?"  Easy!
> 
> 	mktemp ("/tmp/fooXXXXXX");
> 
> 		becomes
> 
> 	mktemp ( (char *) "/tmp/fooXXXXXX");

Even better, it becomes

	char tempstr[14+1];

	strcpy(tempstr, "/tmp/fooXXXXXX");
	mktemp(tempstr);

which can, unlike

	mktemp("/tmp/fooXXXXXX");

be executed more than once and work every time.
-- 
	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list