|
-
June 26th, 2008, 01:53 AM
#1
how to print only N numbers of string
Hello all
beginners question :
i have code that receives string buffer the buffer size is 128
but i like to print to console the string that actually receives , it can be 10 characters long or 5 or 20
i have :
...
int rec_result;
int lens = 128;
char buf[128];
rec_result = recv(new_fd,(char*)buf,lens,0);
// now i like to print only the buf string
// this code dos not work because i can't set the char array like this
// what is the alternative ?
int u = rec_result+1;
char bufprintout[6];
strncpy(bufprintout,buf,rec_result);
bufprintout[rec_result+1]='\0';
printf("server recv:%s",bufprintout);
what is the proper way to do that ?
-
June 26th, 2008, 02:54 AM
#2
Re: how to print only N numbers of string
Code:
int rec_result(0);
int lens(128);
char buf[128] = {};
rec_result = recv(new_fd, (char*)buf, lens, 0);
std::cout << buf;
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|