#why it is giving me an error...? help pls
25 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
thas the error
#include<string.h>
void copy (char* dst, char* src) {
while (*src != '\0') {
strcpy(*dst, *src);
src++;
dst++;
}
*dst = '\0';
}
int main () {
char srcString[] = "We promptly judged antique ivory buckles for the next prize!";
char dstString[strlen(srcString)+1];
copy(&dstString[0], &srcString[0]);
printf("%s\n%s", srcString, dstString);
}
i still cant figure it out...
but i changed strcpy(*dst, *src) for *dst = *src; and worked
i just dont understand why with strcpy was not working
@crisp wagon Has your question been resolved? If so, run !solved :)
!solved
Thank you and let us know if you have any more questions!
You are using that method incorrectly. You dont need a loop to copy the string content , just strcpy without loop works
i was using pointers to move forward in the array, that why i used loop
i just needed to take off the derefere operator and worked, strcpy already use pointers
so just strcpy(dst, src) works like *dst = *src
you dereference the strings. take the stars away from strcpy call
oh there was discussions
If this is supposed to be C then don't name the file stringCopy.cpp.
#include<stdio.h>
#include<string.h>
void copy (char* dst, char* src) {
strcpy(dst, src);
}
int main () {
char srcString[] = "We promptly judged antique ivory buckles for the next prize!";
char dstString[strlen(srcString)+1];
copy(&dstString[0], &srcString[0]);
printf("%s\n%s", srcString, dstString);
}
**output: **
We promptly judged antique ivory buckles for the next prize!
We promptly judged antique ivory buckles for the next prize!
loop not needed
the hexadecimal address of srcString[0] is the same as the srcString, right? so if i change to 1 or another number, it wouldnt work, just for 0...
i was learning at codecademy, the file was already created, either way ill keep it in mind