#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Galway, Ireland
    Posts
    4
    Rep Power
    0

    Question string dissapearing problem using strcpy and strcat


    /*Hey all.....I have a little problem.*/

    /*I create a string and initialise it*/

    char longstring[250];
    strcpy(longstring, "host-");

    /*I also have another string query[500] and later in the code I initialise that.....then I add to it using strcat*/

    /*THEN, for some mystical reason.....longstring[250] has, ummm.....dissapeared.....(longstring == "").....funny, huh? especially seeing as it isn't mentioned in the code AT ALL inbetween the points when it's there and when it's not*/

    /*one other thing I noticed is that while all this is going through a loop, after a while, (longstring == 0), then after another while, (longstring == 00)......???????*/

    anyone have any idea what's going on??????

    thanks,

    Des.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Galway, Ireland
    Posts
    4
    Rep Power
    0
    ok, I figured it out........

    char buffer[5],
    char longstring[250];

    buffer was being past a string representation of integers in most cases.....but in one it was being passed a double (from sprintf).....[5] was not big enough to hold , say, 100.000000 ......so it was passing the last few digits into the next string, longstring....which is why it was printing 0, then 00......etc.

    thanks anyways

IMN logo majestic logo threadwatch logo seochat tools logo