Pelles C > General discussions

need help with sprintf

(1/1)

post from old forum:
char* format="                ";  // 16 spaces
char* Result[22] ;
int p=12;
sprintf(format, "%%.%df", p);
sprintf(Result, format, *d);

what is wrong with the above code?
it crashes on my PC, any help is appreciated.

post from old forum:
I think the problem is with the variable format. You initialize it with a literal string. In Pelles C (and several other C compilers), literal strings are put in read-only memory. Writing to read-only memory will cause an exception.

Pelle

Navigation

[0] Message Index

Go to full version