Appending strings in C

前端 未结 6 1854
无人共我
无人共我 2020-12-12 02:21

How do I combine multiple strings. For example,

char item[32];
scanf(\"%s\", item);
printf(\"Shopping list: %s\\n\", item); //I want to combine this string          


        
6条回答
  •  难免孤独
    2020-12-12 02:50

    You can use sprintf:

    char combinedstring[100];
    sprintf(combinedstring,"%s %s %s",item,string_2,hw);
    

    You can also look up the string.h header and its functions.

提交回复
热议问题