0

Because I know that

char array[STRING_ELEMENTS + 1][MAX_STRING_LENGTH + 1];

/*just for the first element*/
array[0] == ("this number: %d, and that number: %d\n", a, b);

probably makes me look disgusting. I would have no clue how else to do this though.

6
  • You mean the problem that you have to use MAX_STRING_LENGTH? Commented Sep 17, 2015 at 13:29
  • You title is confusing . Commented Sep 17, 2015 at 13:31
  • @ameyCU sorry I'm very new to this. What do you suggest I name it to? Commented Sep 17, 2015 at 13:31
  • @Superlokkus I don't understand? Commented Sep 17, 2015 at 13:32
  • @Laefica The problem is: If your string gets longer than MAX_STRING_LENGTH because of the variables, snprintf which you must use for a safe program, will truncate you string. Commented Sep 17, 2015 at 13:44

1 Answer 1

4

You can't assign a string like this in C, but you can use snprintf:

snprintf(array[0], MAX_STRING_LENGTH, "this number: %d, and that number: %d\n", a, b);

(don't forget to #include <stdio.h> somewhere near the top of your program.)

Sign up to request clarification or add additional context in comments.

1 Comment

and #include <stdio.h> (for snprintf(3) function) also.

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.