Hi
snprintf is working fine when i am not using append function . But as soon as i use append function snprintf crashes . Please suggest
why snprintf is crashing after append . What is special with append function which is crashing this program
Below is the program.
#include<string>
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
char *s;
string name="ESACPE ";
name.append("hello '\\' ");
cout<<snprintf(s,30,name.c_str());
getch();
return 0;
}
tom_jerry042 0 Newbie Poster
Recommended Answers
Jump to PostRead this
http://www.daniweb.com/forums/announcement8-3.htmlThen allocate some memory for s before trying to write data.
Jump to PostAs opposed to say crashing when you do this?
char *s; string name="ESACPE "; cout<<snprintf(s,30,name.c_str());
Who knows, dumb luck perhaps.
It's certainly got the potential to crash at any moment.> name.append("hello '\\' ");
The fact that this made it crash does NOT imply that your …
All 6 Replies
Salem 5,265 Posting Sage
ArkM 1,090 Postaholic
tom_jerry042 0 Newbie Poster
Salem 5,265 Posting Sage
tom_jerry042 0 Newbie Poster
iDeveloper 21 Light 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.