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

    Join Date
    Jul 2003
    Location
    Waterloo, ON.
    Posts
    4
    Rep Power
    0

    Messed up string output in C


    Hello,

    I am a newbie working with strings in C, and I have ran into this problem where the rear part of the string that is printed (using printf() ) is messed up.

    Code:
    {

    ....
    char *finalExp = Pop(&exps);
    printf("Final Expression\n");
    printf("%s\n",finalExp);

    }

    I am using a stack that stores pointers to strings, and Pop(stack *s) operation pops and returns the top item of the stack.

    Output:

    Final Expression
    .....(out3val)) & ((next(out2val)) = (out2``)))

    but it should be:

    Final Expression
    ......(out3val)) & ((next(out2val)) = (out2val)))))))

    What could be the cause for this problem? Is there any way to fix it?

    Thank you in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    138
    Rep Power
    12
    Well, I dont see any problem in the code except that the size of the char array in the pop function may be less and hence it might be returning you the garbage at the end.

IMN logo majestic logo threadwatch logo seochat tools logo