2

Is there a simple way to set the value of a variable to the concatenated values of other variables of mixed types?

For example, something that accomplishes the same thing as this...

int card=10;
char card_suit='c';
char card_picture[255];
FILE *x


x=fopen("streamy.txt", "w");
fprintf(x, "%d%c.bmp\n", card, card_suit);
fclose(x);

x=fopen("streamy.txt", "rt");
fscanf(x, "%s", &card_picture);
fclose(x);

But not dumb.

Am I missing something super obvious?

1 Answer 1

5

I believe you're looking for snprintf() and its relatives:

char card_picture[255];

snprintf(card_picture, sizeof(card_picture), "%d%c.bmp", card, card_suit);
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.