Reputation:
Let's say I've got this piece of code:
void copyElement(int n, char source[100])
{
char s;
strcpy(s, source[n]);
}
I will get some errors and it won't work.
What would be the proper way to do it?
Upvotes: 0
Views: 301
Reputation: 172
strcpy takes pointers to characters and not characters, what you could do is
void copyElement(int n, char source[100])
{
char * s = (char *) malloc (1) ;
strcpy(s, &source[n]);
}
Upvotes: -1
Reputation: 1218
You can do it directly. If you want to copy a char
of a specific position you can use
char c = source[index_of_array];
Upvotes: 3