strcat() won't exit

Posted by Tristan Sebens on Stack Overflow See other posts from Stack Overflow or by Tristan Sebens
Published on 2012-12-07T22:50:55Z Indexed on 2012/12/07 23:04 UTC
Read the original article Hit count: 183

Filed under:
|

I'm trying to implement a very basic server in C, one part of which is constructing HTTP headers. To do this I have written a class called header_builder, which basically constructs the headers for me. One of the most basic methods of this class is append_header_line, shown below:

void append_header_line( const char *line, char *hdr ) {
  printf("Adding header line\n");
  strcat( hdr, line );
  printf("Line added. Adding ending.\n");
  strcat( hdr, "\r\n" );  
  printf("Success\n");
}   

All it's supposed to do is tack the "line" parameter onto the end of the "hdr" parameter, and then add "\r\n" to the end of it all. The problem is that the first strcat call never exits. When I run this code, all it does is say:

Adding header line

Which means that the following lines never execute, and I can't figure out why. Any thoughts?

© Stack Overflow or respective owner

Related posts about c

    Related posts about strcat