Code:
int main(void)
{
char user[50] = "testuser@123456";
char userTwo[50] = "jabman@999";
printf("\n\nUser string created");
registerUser(user);
printf("\n\nUser registered");
printf("\n\nget username");
char uname[50];
getUsername(user, uname);
printf("\n\nThe returned user name was : %s ", &uname);
strcat(uname, "@");
printf("\n\nThe returned user name is now : %s ", &uname);
if(searchForUser(uname)==1)
{
printf("\n\ntrue User %s found", user);
}
else
{
printf("\n\nfail real user find");
}
printf("\n\nTry and get password");
char pass[50];
getPassword(uname, pass);
printf("\n\nThe returned password was : %s \n\n", pass);
}
Code:
...
void getPassword(char *username, char *password)
{
FILE *logon_file;
logon_file = fopen("users.txt", "r+a");
char tmp[100];
int userLength = strlen(username);
char tempPassword[50];
while(fgets(tmp, 100, logon_file))
{
if(strstr(tmp, username))
{
tempPassword = &tmp;
int i;
for(i = 0; i<userLength; i++)
{
tempPassword++;
password = tempPassword;
}
}
}
fclose(logon_file);
}
....
I get:
The returned password was : ��
The problem is in the getPassword function shown above.
Basically, I have a txt file (users.txt) containing passwords and user names
One username/password combo per line
Each username seperated from its password with a '@' symbol
The function should take a username, find the line containing that name
e.g.
"thisIsTheNameIWanted@password"
It should then advance the pointer on the above string by the length of the username string and result in the password parameter being set to the password portion only.
Sorry if this doesnt make sense. I wrote a detailed description then my connection was lost and I've had to redo quickly. I will be happy to clarify anything.
Again, I appreciate all the help this forum gives me.