How to insert a string in another string in C -
i need insert string in string @ specific place. here's simple example:
char *a = "dany s."; char *b = "my name *a , come ... ";
so, in string b
in place of *a
expect have dany s.
how ?
the best/easiest way use standard c conventions:
char *a = "dany s."; char *b = "my name %s, come from..."; char *c = malloc(strlen(a) + strlen(b)); sprintf( c, b, );
then c
contains new string. when you're done c
, need free memory:
free( c );
if want use c
in output terminates line, can declare b
as:
char *b = "my name %s, come from...\n";
Comments
Post a Comment