• C

concat two array

char input[60];
char inputType[60];
char result[1024];

cout<<"Please type your input"<<endl;
gets(input);

cout<<"Please type your input type"<<endl;
gets(input type);


I am not sure the input and inputType array size. I need and put input and add '_'  and inputType into result array. how ? please hlep.

for exampel, user type "input" and "type", and result array should be input_type
keepworkingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tim_UtschigCommented:
Use strcpy() and then two strcat() calls.

And you're mixing C and C++ code.   If you want to use C, use printf(), not cout.
amit_gCommented:
#include <string.h>

result[0] = '\0';
strcat(result, input);
strcat(result, "_");
strcat(result, inputType);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kent OlsenDBACommented:
Hi keepworking,

For the record, it's "traditional" to use strcpy() to put the first string in the buffer and scrcat() to append additional strings.

Just for future knowledge, you could have done this with a single statement.  :)

  sprintf (result, "%s_%s", input, inputType);


Good Luck!
Kent
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.