what the... C code problem
Hi all,
I clearly am suffering from a fundemental lack of understanding. What is wrong with the following code snippet? Code:
#define _GNU_SOURCE TIA. |
strcpy( a, ( char * ) b );
This isn't doing what you think it's doing. Its attempting to access memory location 100 and copy that to a. Which is why you have the segmentation fault. sscanf( a, "%d", b ); |
Hi,
Thanks. You were right--that wasn't doing at all what I thought it was. When I try sscanf, I get a warning: junk.c:15: warning: format argument is not a pointer (arg 3) And then the printf prints just the newline. Ideas? Thanks again. |
I think you need this:
Code:
a=(char *)malloc(4); |
Yep Matir is right mixing up my scan and my print.
|
Thank you both, all fixed now and ready to roll for a while!
Thanks again! |
No problem. Feel free to click the thanks button by my post... not that I know what it does, lol. :)
|
All times are GMT -5. The time now is 05:40 AM. |