#why it is giving me an error...? help pls

25 messages · Page 1 of 1 (latest)

crisp wagon
grizzled totemBOT
#

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.

crisp wagon
#

thas the error

crisp wagon
#
#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);
}
wind hollow
#

Check this for strcpy

crisp wagon
#

but i changed strcpy(*dst, *src) for *dst = *src; and worked

#

i just dont understand why with strcpy was not working

grizzled totemBOT
#

@crisp wagon Has your question been resolved? If so, run !solved :)

crisp wagon
#

!solved

grizzled totemBOT
#

Thank you and let us know if you have any more questions!

wind hollow
#

You are using that method incorrectly. You dont need a loop to copy the string content , just strcpy without loop works

crisp wagon
#

i just needed to take off the derefere operator and worked, strcpy already use pointers

#

so just strcpy(dst, src) works like *dst = *src

edgy cargo
#

you dereference the strings. take the stars away from strcpy call

#

oh there was discussions

verbal scroll
#

If this is supposed to be C then don't name the file stringCopy.cpp.

wind hollow
#

**output: **

We promptly judged antique ivory buckles for the next prize!
We promptly judged antique ivory buckles for the next prize!

#

loop not needed

crisp wagon
crisp wagon