I want this program to return an array, and then a variable from main to get this array from the function, and be usable in a part of code that has to verify a string against these values from the initial variable. But the variable doesn't get the returned array. I've seen some posts saying that you cannot return arrays in C, but I've also seen other post where this was possible.
But I want to know what can I do to catch this returned value.
int getUsers()
{
char userVect[5][25];
char user[24];
int i = 0, j = 0, k;
FILE *usernames;
usernames = fopen("usernames.cfg", "r");
if (usernames == NULL){
perror("usernames - err");
return(-1);
}
while(fgets(user, sizeof(user), usernames) !=NULL){
strcpy(userVect[j], user);
j++;
}
fclose(usernames);
for(k=0; k<j; k++)
printf("Usernames are: %s\n", userVect[k]);
return userVect;
}
int main()
{
printf("\nWelcome to Sys v1.24. To start off, please insert your command. \n");
char *users;
users = getUsers();
printf("%c\n", users);
return 0;
}