i am trying to use memcpy but it gives me a compile error
this is what i am doing
Code:char *temp; char space[21]; temp = malloc(5000); strncpy(space, " ", 21); memcpy(temp, space, 21);
what is wrong?
i am trying to use memcpy but it gives me a compile error
this is what i am doing
Code:char *temp; char space[21]; temp = malloc(5000); strncpy(space, " ", 21); memcpy(temp, space, 21);
what is wrong?
What error might that be?Originally Posted by mbooka
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
the errors is on the memcpy line
my error that i get or the error i think is wrong with the code?
if it is the first one all i get is
"pass error"
after looking at my code for a couple of minutes i realise that it was my stupid fault and left out a small but significant ';'.
...
This is why we copy the code into our post and not rewrite it.
Sent from my iPadŽ
You may want to consider doing something like this.Originally Posted by mbooka
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { size_t size = 21; char *temp = malloc(size); if ( temp != NULL ) { memset(temp, ' ', size - 1); temp[size - 1] = '\0'; printf("temp = \"%s\"\n", temp); free(temp); } return 0; }
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
I will keep that in mind when memcpy doesnt seem to work.
Also with regards to SlyMaelstrom comment, i cant copy my code because i cant copy from cygwin. I work remotely on a unix machine on a windows platform.
Pipe your output to a text file. Open it, copy-paste. Or of course you could simply open up a text editor, type the error out as you see it... or the post box... Yeah, it's not real hard to figure out a way to tell us the actual error if you're not too freeking lazy to do it.
Quzah.
Hope is the first step on the road to disappointment.
> i cant copy my code because i cant copy from cygwin
This is a load of BS - I do this all the time.
All you have to do is click on the properties icon in the title bar and enable editing (just like you would if it were a win32 console window).
Now post accurate information from now on, not heresay ramblings.