Hi all!
I'm a complete nub when it comes to C...I'm learning it as part of my course. I am having trouble on a self learning excercise, and I found another thread about array of strings but it's closed.
Anyway, what I'm trying to do call a sub function from my main function (while passing the array defined in the main function as an argument).
The subfunction then takes that parameter and fills the array via pointers so my main function looks nice and neat and gets all the data it needs.
When I try running it I get the following error on line 28:
error #2140: Type error in argument 1 to 'getnames'; expected 'char * (*)[40]' but found 'char (*)[40]'.
but and I think it's trying to say I've got a data type error but I can't figure out where I'm going wrong. It's probably just a really simple error but I appreciate your wisdom to correct any lines of faulty code!
Below is a sample of my code so far:
Code:
#include<stdio.h>
#define n_max 13
#define max 40
char getnames(char* n[n_max][max])
{
int i, temp;
printf("Please enter names\n");
for (i=0; i<n_max; i++)
{
temp = n_max-i;
scanf("%s", *n[i]);
printf("%d-1 names remaining\n",temp);
i++;
}
return(0);
}
int main (void)
{
int i = 0;
char names[n_max][max];
getnames(names);
for (i=0; i<n_max; i++)
{
printf("%s\n", names[i]);
printf("completed\n");
}
getchar();
getchar();
return(0);
}
thanks in advance