0

How to combine multiple lines into one line in c?

Example1: Input: I want to eat an apple. Output: I want to eat an apple. Example2: Input: I want to meet my mother and father. Output: I want to meet my mother and father.

1st Jun 2022, 8:27 AM
Smokie Raccoon
1 Antwort
0
Basically you want to merge 3 strings, so prepare a result buffer (char array) big enough to contain the 3 strings, the spaces in between, and one null character for string terminator. Then you can use strncat() function from <string.h> to copy the 3 strings content into the result buffer. You can make use of a loop in case there are many strings to be merged e.g. when the strings to be merged are array elements. http://www.cplusplus.com/reference/cstring/strncat/
1st Jun 2022, 8:35 AM
Ipang