I am writing a function that searches for a text file formatted as follows:
# User1 \ transfer
\
# User2 \ transfer \ # User3 \ transfer \
I wrote the Check_User function:
int Check_User(char input[20], FILE *userlist)
{
int c, i;
fseek(userlist, 0, SEEK_SET);
while(1)
{
while((c = fgetc(userlist)) != '#')
{
if(c == EOF)
return 1;
}
while(input[i] == (c = fgetc(userlist)))
{
i++;
}
i = 0;
if(c == '\\')
return 0;
}
}
What is caused from here:
while(Check_User(username, userlist) == 0)
{
printf("Username already in use. Please select another:");
Get_Input(username);
}
Verify that the user checks the file pointed to by * userlist to see if the username [20] contains a username that is already in use. If it is already in use, it calls Get_Input for the new username.
The program paves the way to the while loop, and then gives me a segmentation error: 11. I read that this is often associated with trying to write outside the array or even do something in memory, I don’t have access. Userlist.txt was opened in r + mode.
Thanks for the help.