0

I'm trying to add an integer to a string. So it's something like this:

pass_value = m + ";" + v1 + ";" + v2 + ";" + v3 + ";" + v4

output would be:

2;23;21;53;34

But that doesn't work. Can you help me, please?

0

1 Answer 1

5

Integers and strings are two different types in C, and there is no way to add them, from your description, what you need is sprintf which will print the integers into a string buffer:

int m, v1, v2, v3, v4;
// do some computes for the integers
char str[512];
snprintf(str, sizeof str, "%d;%d;%d;%d;%d", m, v1, v2, v3, v4);
printf("result is %s\n", str);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.