I need to figure out how to append an int to a string, so basically i need to convert the int to a string 1st, but I cant figure out how. :rolleyes: any help would be greatly appreciated. thank you, courtney
cortiknee 0
Newbie Poster
Recommended Answers
Jump to PostGreetings,
This process is not hard since the default libraries included a function to do this. It's called itoa().
» char *itoa(int value, char *buffer, int radix);
Converts an integer value to a null-terminated string using the specified radix and stores the result in the given buffer.
If …
Jump to PostThis process is not hard since the default libraries included a function to do this. It's called itoa().
And itoa is nonstandard. A standard function is sprintf.
#include <stdio.h> int main(void) { const char base[] = "filename"; char filename [ FILENAME_MAX ]; int number = 42; sprintf(filename, …
Jump to Postsprintf(filename, "%s%d", base, number);
Ah, yes. Though remember sprintf() does not calculate for buffer overflow. sprintf() doesn't flush any file buffer, in fact it doesn't have any buffer associated with it. sprintf() operates on a character buffer (not quite the same thing). If you overflow that buffer …
Jump to Post>Though remember sprintf() does not calculate for buffer overflow.
Neither does itoa. ;)>A safer version of sprintf() is snprintf() which unfortunately isn't very standard yet.
It is standard, but the standard just isn't widely implemented yet. As it is, C89 is the dominant C standard, and snprintf is …
Jump to Post» Neither does itoa.
Exactly, though now there is a working prototype. It wouldn't be hard for someone to modify it and make it safer. It is alot better off than re-writing sprintf().» It is standard, but the standard just isn't widely implemented yet.
…
Standard only in C99.
All 21 Replies
Stack Overflow 8
Junior Poster
Dave Sinkula 2,398
long time no c Team Colleague
Stack Overflow 8
Junior Poster
Narue 5,707
Bad Cop Team Colleague
Stack Overflow 8
Junior Poster
Dave Sinkula 2,398
long time no c Team Colleague
Narue 5,707
Bad Cop Team Colleague
spincycle 0
Newbie Poster
WaltP 2,905
Posting Sage w/ dash of thyme Team Colleague
~s.o.s~ 2,560
Failure as a human Team Colleague Featured Poster
Salem 5,138
Posting Sage
mcldev 0
Light Poster
Dave Sinkula 2,398
long time no c Team Colleague
dverex 0
Newbie Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
dverex 0
Newbie Poster
deceptikon 1,790
Code Sniper Team Colleague Featured Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
dverex 0
Newbie Poster
Ancient Dragon 5,243
Achieved Level 70 Team Colleague Featured Poster
dverex 0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.