send data on socket adds strange chars to string

B

barncat

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
 
E

Eric Sosman


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top