c++ - Function to validate a value returns true when it calls 1 digit, but when its 2 or more it returns false even when it's true -
so have been @ problem few hours , have no thought what's wrong. function returns true or false if int called valid one. when phone call valid number 1 digit long "0", or "1" returns true. when phone call number bigger 1 digit "83" or "955" should homecoming true, returns false when should homecoming true!
my validator function:
int isregistered(file* file, int area) { int areadigit = 0; int check = 0; while(fscanf(file, "%d %*[^ ] %*[^\n]", &areadigit) != eof) { if (area == areadigit) check = 1; } homecoming check; and code calls function:
( = 0; < areacounter; i++) { cout << areaint << endl; areacheck = isregistered(file, areaint); if (areacheck != 1) areaint = areaint * 10 + areainta[i+1]; } if value of areainta[3] = 955, loop calls, 9, 95, 955 until no longer has digits call. 955 should homecoming true because value true reason returning false.
when phone call '0' or '1' true, returns true larger 1 digit returns false. know why?
the function isregistered reads file end, , never rewind it. first phone call isregistered works ok, next ones never come in while loop because fscanf returns eof.
if isregistered meant search whole file, seek this:
int isregistered (file * file, int area) { int areadigit = 0; rewind (file); // go origin of file , clear flags while (fscanf (file, "%d %*[^ ] %*[^\n]", &areadigit) != eof) if (area == areadigit) homecoming 1; homecoming 0; } c++
No comments:
Post a Comment