I have this program in C and I'm trying to get strings from a file and put them in a array. It works perfectly for reading the file, but seems it messes up with the assign in the array.
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(!feof(usernames)){
fgets(user, sizeof(user), usernames);
strcpy(userVect[j], user);
j++;
}
fclose(usernames);
for(k=0; k<j; k++)
printf("Usernames are: %s\n", userVect[j]);
return 0;
}
It's surely from the user variable, or from the strcpy function, but not sure what. Thx.