Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > send data on socket adds strange chars to string

Reply
Thread Tools

send data on socket adds strange chars to string

 
 
barncat
Guest
Posts: n/a
 
      05-12-2010
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:
/,/,Typeedicated
Mode:Capped
--

Thanks,
Jim
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      05-12-2010
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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
 
 
 
barncat
Guest
Posts: n/a
 
      05-12-2010
On May 12, 2:08*pm, Eric Sosman <(E-Mail Removed)> 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
> (E-Mail Removed)


sorry for the multi-post.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
How to truncate char string fromt beginning and replace chars instring by other chars in C or C++? Hongyu C++ 9 08-08-2008 12:18 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
receiving ??? chars instead of "special" chars M.Posseth ASP .Net Web Services 3 11-16-2004 07:00 PM



Advertisments