I want to add \"\" to {\"status\":true} so that the string looks like \"{\"status\":\"true\"}\". How can I insert characters to a stri
Use sprintf().
const char *source = "{\"status\":\"true\"}";
/* find length of the source string */
int source_len = strlen(source);
/* find length of the new string */
int result_len = source_len + 2; /* 2 quotation marks */
/* allocate memory for the new string (including null-terminator) */
char *result = malloc((result_len + 1) * sizeof(char));
/* write and verify the string */
if (sprintf(result, "\"%s\"", source) != result_len) { /* handle error */ }
/* result == "\"{\"status\":\"true\"}\"" */