send data on socket adds strange chars to string

Discussion in 'C Programming' started by barncat, May 12, 2010.

  1. barncat

    barncat Guest

    hi
    I am reading data from a popen call (server) and sending the data to a
    client. It works fine except funny chars are prepended to the string
    sent and displayed at the client. here is the relevant code:
    --
    FILE *FP;
    char string[32];
    char buf[128];
    FP = popen("lparstat -i | head -5 | tail -2","r");
    while(fgets(buf,128,FP) != NULL) {
    strcat(string,buf);
    squeeze(string); //function to remove spaces
    }

    pclose(FP);
    if (send(socket, string, strlen(string), 0) == -1)
    perror("Writing String to client");
    --
    /* function to remove spaces */
    int squeeze(char *s) {
    char *t = s;
    for(;*s;(*s != ' ') ? *t++ = *s++ : *s++)
    continue;
    *t = '\0';
    }

    --

    Output from client:

    -bash-2.05b$ ./program
    received answer to query from server:
    /ò,¸/ò,ÀType:Dedicated
    Mode:Capped
    --

    Thanks,
    Jim
     
    barncat, May 12, 2010
    #1
    1. Advertising

  2. barncat

    Eric Sosman Guest

    On 5/12/2010 2:06 PM, barncat wrote:
    > hi
    > [...]


    Please don't multi-post. If you *must* communicate with
    more than one newsgroup, cross-post instead.

    Your question has already been answered on comp.unix.programmer.

    --
    Eric Sosman
    lid
     
    Eric Sosman, May 12, 2010
    #2
    1. Advertising

  3. barncat

    barncat Guest

    On May 12, 2:08 pm, Eric Sosman <> wrote:
    > On 5/12/2010 2:06 PM, barncat wrote:
    >
    > > hi
    > > [...]

    >
    >      Please don't multi-post.  If you *must* communicate with
    > more than one newsgroup, cross-post instead.
    >
    >      Your question has already been answered on comp.unix.programmer.
    >
    > --
    > Eric Sosman
    >


    sorry for the multi-post.
     
    barncat, May 12, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kosio

    Floats to chars and chars to floats

    Kosio, Sep 16, 2005, in forum: C Programming
    Replies:
    44
    Views:
    1,342
    Tim Rentsch
    Sep 23, 2005
  2. Hongyu
    Replies:
    9
    Views:
    966
    James Kanze
    Aug 8, 2008
  3. M.Posseth

    receiving ??? chars instead of "special" chars

    M.Posseth, Nov 15, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    285
    Dan Rogers
    Nov 16, 2004
  4. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    237
    Chris Reay
    Nov 4, 2003
  5. Ryan Parmeter
    Replies:
    4
    Views:
    263
    Douglas Wells
    Sep 5, 2007
Loading...

Share This Page