I want to make simple login,register system. and register part is done, but login part is little confuse..
Login with Txt file. Filename - ID, file including "Nickname|PW"
then scanf ID first, if id exist -> get PW and open ID txt file to compare pw.
I'm tried fgets and fread and more... but i dont know exactly how to use them
int ckk; // position of "|"
ck_pw = fopen(fpp_id, "r"); //open ID txt file to read including text
for (int j = 0;; j++) { // count where is "|"
char buf; // buffer
buf = '\0'; //reset buf
fread(buf, j, 1, ck_pw);
if (buf == '|') { //find "|"
ckk = j + 1;
break;
}
}
fseek(ck_pw, ckk, SEEK_CUR); //move cursor to "|"
for (int k = 0;; k++) { //read text before space(NULL)
fread(pw_ck, k, 1, ck_pw);
if (pw_ck[k] == NULL) {
break;
}
}
I used an uninitialized "ck_pw" local variable. in Visual studio 2017
freadreturn value.for (int j = 0;; j++)andfor (int k = 0;; k++)are endless loops, in case there is no|in the file,pw_ck[k] == NULL- you are comparingcharwith avoid*(assumingpw_ckis somechar[?]pointer and is valid), the code is incomplete (mainis missing and relevant#includes, also the declarations ofck_pw,fpp_id,pw_cketc. is missing), you don't check the return value offreadnor offopennor offseek. The second loop doesn't make any sense, you are readingkcharacters and increment k endlessly, the code will not work as intended