networking - C - manipulating stdin or stdout -


im writing simple chat program.
trying do, display username in front of chat messages (other people have server).
see few methods of doing this.
either block output somehow (for example not outputting stdin or removing last line stdout) , let server handle username concat, or manipulate stdin/stdout , prefix line username on clientside.
problem is, don't know how neither , googling isn't helpful.

heres code snippet of main loop:

while(1){     //printf("while runs\n");     readfds_buffer = readfds;      rv = select(sockfd+1, &readfds_buffer, null, null, &tv);      if (rv == -1) {         perror("select");     } else if (rv != 0) {         if (fd_isset(sockfd, &readfds_buffer)) {             if ((numbytes = recv(sockfd, buf, maxdatasize-1, 0)) == -1) {                 perror("recv");                 exit(1);             }              //buf[numbytes-1] = '\n';             buf[numbytes] = '\0';             if (numbytes > 1) {                printf("%s",buf);            }         }         if (fd_isset(0, &readfds_buffer)) {             if (fgets(str, 79, stdin) != null){                 send(sockfd, &str, sizeof(str), 0);             }         }     }    } 


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -