|
-
Aug 4th, 2001, 05:47 AM
#1
Thread Starter
PowerPoster
just a simple| simple QUESTION:)
i was just playing around with the web server and found that I did not know one thing.
When I declare a variable like this:
char buf[1000];
--
Now when I put this code in:
e = 0;
buf[e] = "\\";
--
Will
buf[e]
have the string "\\" ?
And if I do something like this
buf[e] = 0;
Will it erase the string already in buf[e] , which is "\\", or will it leave this string in there ?
Please, that is a kind of urgent, and I know that is just a little newbie answer for you
-
Aug 4th, 2001, 06:32 AM
#2
Monday Morning Lunatic
Code:
e = 0;
buf[e] = "\\";
This won't work because "\\" is a string. Try using '\\\\'. However, since buf[e+1] probably won't be '\0' anything that tries to print a string will fail.
Last edited by parksie; Aug 4th, 2001 at 06:36 AM.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 06:37 AM
#3
Monday Morning Lunatic
OK something's gone screwy so the character to use is: ' \ \ ' (that's got double spaces in)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 07:14 AM
#4
Thread Starter
PowerPoster
No, I am using "\\" (without any space between then)
It is working fine. The server can display the spcific file but because It was a tutorial, and I am not getting this code ( I am not understanding why and what it is doing)
Code:
d=recv(wparam,aa,1000,0);
abc(aa);
p=aa + 4;
e=0;
while(*p!=32)
{
if (*p=='/')
{
buf[e]='\\';
}
else
buf[e]=*p;
if(buf[e]=='.')
fn=1;
p++;
e++;
}
buf[e] = 0; //PLEASE SEE BELOW
`
if (strlen(buf)==1)
strcpy(filename,"c:\\website\\woo\\index.html");
else
{
strcpy(filename,"c:\\website");
strcat(filename,buf);
if(fn==0)
strcat(filename,"index.html");
}
I am also confused at this line where I commented in red colour
buf[e] = 0
Why do I need put it back to 0?
-------------------
You are intelligent enough to know this parskie! Are not you
Last edited by abdul; Aug 4th, 2001 at 07:29 AM.
Baaaaaaaaah
-
Aug 4th, 2001, 07:15 AM
#5
Thread Starter
PowerPoster
Ohh, Another thing in the code:
abc() is just function to write the given characters to a file
-
Aug 4th, 2001, 11:14 AM
#6
Monday Morning Lunatic
Since e has been incremented, it will ensure that the string is null-terminated
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|