Okay so I have the following Code which appends a string to another in C#, note that this is Just an example, so giving alternative string concatination methods in C# is not nessesary, this is just to simplify the example.
string Data = "";
Data +="
HTTP/1.1 " + Status_code;
Data += "
Content-Type: " + Content_Type;
Data += "
Server: PT06";
Data += "
Content-Length: " + Content_Lengt;
Data += "
Date: " + Date;
Data += "
" + HTML;
Now I'd like to do the exact same thing in C and I'm trying to do this the following way
time_t rawtime;
time ( &rawtime );
char *message = "
HTTP/1.1 ";
message = strcat(message, Status_code);
message = strcat(message, "
Content-Type: ");
message = strcat(message, Content_Type);
message = strcat(message, "
Server: PT06");
message = strcat(message, "
Content-Length: ");
message = strcat(message, Content_Lengt);
message = strcat(message, "
Date: ");
message = strcat(message, ctime(&rawtime));
message = strcat(message, "
");
message = strcat(message, HTML);
Now, this gives me a Segment fault, I know why, I access and read on memory that i shouldn't. But the question is, how do i solve it? Could I use string.h and just do it the same way that I did in C#?
See Question&Answers more detail:os