this is my first (and I hope last) C language coding. It is for my coursework and I have some troubles.
main(){
char asd[20] = {"asd"};
insert(asd);
}
void insert(char value[]) //here value[] contains only 'd'
{
...code...
}
main(){
char *asd[20] = {"asd"};
insert(asd);
}
void insert(char *value[]) //here value[] contains 'asd'
{
char *secondArray[20] = {' '}
strcpy(secondArray,value); // char** incompatible with "const char*"
}
You have not declared your strings correctly, they should be char arrays not array for char pointers
char *asd[20] = {"asd"};
to
char asd[20] = {"asd"};
and
char *secondArray[20] = {' '}
to
char secondArray[20] = {' '}
Program after corrections:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void insert(char *value);
int main(){
char asd[20] = {"asd"};
insert(asd);
return 0;
}
void insert(char *value) //here value[] contains 'asd'
{
char secondArray[20] = {" "};
strcpy(secondArray,value); // char** incompatible with "const char*"
printf("%s",secondArray);
return;
}