By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

segmentation fault with sprintf

bajajv
100+
P: 152
Hi, I am trying to convert integer to string.

this is my code -

Expand|Select|Wrap|Line Numbers
  1. long num = 23456789;
  2. char buff[20];
  3. sprintf(buff, "%s", num);
  4. printf("%s\n", buff);
  5.  
but I am getting segmentation fault in sprintf() call.

Any idea why this is coming?
Nov 25 '10 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
That is because you have used %s which is the code for a string and then passed an integer.
Nov 25 '10 #2

Expert 100+
P: 2,400
By the way, when you replace "%s" with the format code for an integer, don't forget to include a qualifier indicating that it is a long integer.
Nov 26 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.