I want to know why the first code works but the second one doesn't.
#include <stdio.h>
#include <string.h>
int main()
{
char *last, *first, *middle;
char pres[20] = "Adams, John Quincy";
char pres_copy[20];
strcpy(pres_copy, pres);
last = strtok(pres_copy, ", ");
printf("%s", last);
first = strtok(NULL, ", ");
printf("%s", first);
middle = strtok(NULL, ", ");
printf("%s", middle);
}
#include <stdio.h>
#include <string.h>
int main()
{
char last[20], first[20], middle[20];
char pres[20] = "Adams, John Quincy";
char pres_copy[20];
strcpy(pres_copy, pres);
last = strtok(pres_copy, ", ");
printf("%s", last);
first = strtok(NULL, ", ");
printf("%s", first);
middle = strtok(NULL, ", ");
printf("%s", middle);
}
I thought array names were the same as pointers.
But the compiler is making a distinction, since it told me type 'char [20]' and type 'char *' was incompatible.
How and why are the two data types different?