main.c
#include <stdio.h>
#include <stdlib.h>
#define MAX_USERS 100
typedef struct Utilizadores{
char *login;
char *pwd;
} USERS;
void ReadUsers(USERS user[]);
int u = 0;
int main(){
USERS user[MAX_USERS];
ReadUsers(user);
return 0;
}
void ReadUsers(USERS user[]){
FILE *fp;
fp = fopen("/home/Jiwe/Desktop/users.txt", "r");
while(fscanf(fp, "%s[^=]=%s\n", user[u].login, user[u].pwd) != EOF){
u++;
}
fclose(fp);
}
Hey guys, I get a segmentation fault error using the code above. For now I just want to read the login name and password of a user from a text file, so later I can show it.
The text file is filled like this:
LOGIN=PASS
LOGIN2=PASS2
... etc
I just don't understand why I'm getting that error, I've been searching for hours for a solution and still haven't found one.