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 :
Code:int rec_result; int lens = 128; char buf; 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; strncpy(bufprintout,buf,rec_result); bufprintout[rec_result+1]='\0'; printf("server recv:%s",bufprintout);
what is the proper way to do that ?