c++ - Creating my own strcopy function -
i trying create own str copy function. error telling me strcopy not declated in scope strcopy(deck[i].suit,source[]); wehre error occurs. please!
#include <fstream> #include <iostream> using namespace std; struct{ char suit[]; char rank[]; int cvalue; }; int main() { char source[] = "name"; cards deck[52]; strcopy(deck[].suit,source[]); } void strcopy(char destination[], char source[]) { for(int i=0; source[i] != '\0' && destination[i] != '\0'; i++) { destination[i] = source[i]; } }
first of forgot specify name of structure. think should have name cards
also arrays defined within structure have defined having sizes.
struct{ char suit[]; // size of array? char rank[]; // size of array? int cvalue; };
function strcopy
has declared before isage.
and function wrong.
i not invent new algorithm of function , write following way
char * strcopy( char destination[], const char source[] ) { char *p = destination; while ( *p++ = *source++ ); return destination; }
Comments
Post a Comment