On Fri, 05 Sep 2003 23:31:27 +0200
Robert <R.****@hetnet.nl> wrote:
Hi,
I am new to c and use to program in basic before so i was
wondering why this isn't working:
char geturl(char *header, int client)
{
char *url;
char *filename;
char *tmpstring;
url = strtok(header, " ");
may return NULL, do error checking
url = strtok(NULL, " ");
may return NULL
if (url == "/")
NO!
You're comparing a pointer to the string 'url' to a pointer to the string
literal "/". This won't be true, EVER, as 'url = "/"' will not nessacerily make
'url' point to the same address.
To see if the first character is '/', do this:
if (*url == '/')
If you want to see if the string is equal to "/", do this:
if (strcmp (url, "/") == 0)
url="index.html";
puts (url);
if url = / then it stay's this way
why? what is wrong with this?
Many thanks,
Robert
I can see you're used to basic, by the way you tried to compare two 'strings'
you did. C doesn't have any string functions 'built in', but there are plenty of
string manipulation FUNCTIONS around to do the job.
Also note that C doesn't have a data type for a 'string'. Here you're comparing
two pointers, pointing to some memory, containing a list of characters,
terminated by character 0 - the null terminator, or '\0' to be correct. What you
want is compare the CONTENTS of the memory pointed to, up until the terminator,
and see if they're both equal.
strcmp (string1, string2) will return <0, 0 or >0 if string1 is considered less
than, equal to or greater than string2. This is what you'll want to use.
strncmp (string1, string2, length) will do the same, but only compare 'length'
bytes of both strings at maximum.
--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}