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 PostAfter that think again. It seems you have wrote absolutely senseless code with this awkward jumble of std::string and C-string oriented snprintf ;)...
All 6 Replies
Salem
5,138
Posting Sage
ArkM
1,090
Postaholic
tom_jerry042
0
Newbie Poster
Salem
5,138
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.