Results 1 to 6 of 6

Thread: just a simple| simple QUESTION:)

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    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
    Baaaaaaaaah

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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

  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Ohh, Another thing in the code:

    abc() is just function to write the given characters to a file
    Baaaaaaaaah

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width