I am trying to create my login system but I have got a problem with reconizing the value from a file. getline(fstream) recognizes it and puts it in a char(reg_confirm), but I can't set a different function for a different value.

it should go like this:

if (value == "0") { // FUNCTION 1 }
else if (value == NULL) {// FUNCTION 2 }
else ERROR

but it always get ERROR. the value in the file is 0.

http://pastebin.com/fMvKgLa8 -- main.cpp

http://pastebin.com/Gj02beva -- defines.h

float IsRegistered()
	char reg_confirm[256];
	/* FILE * llFile;
	long llSize;
	size_t result;
	llFile = fopen (LLOGS_FILE, "r+" );
	if (llFile == NULL) { cout << "reg check error(1)." << endl; exit(1); }
	fseek(llFile, 0, SEEK_END);
	llSize = ftell(llFile);
	reg_confirm = (char*) malloc (sizeof(char)*llSize);
	if (reg_confirm == NULL) { cout << "reg check memory error(2)." << endl; exit(2); }
	result = fread(reg_confirm, 1, llSize, llFile);
	if (result != llSize) { cout << "reg check reading error(3)." << endl; exit(3); } */
	fstream file_op(LLOGS_FILE, ios::in);
	file_op.getline(reg_confirm, 256);
	if (reg_confirm == "0") { RegisterScreen(); }
	else if (reg_confirm == NULL) { cout << "file is null"; }
	else { cout << "error"; exit(99);}
	// fclose(llFile);

Recommended Answers

All 4 Replies

Why don't you cout reg_confirm in your else statement to see why reg_confirm doesn't match or null?

>>char reg_confirm[256];

>>reg_confirm = (char*) malloc (sizeof(char)*llSize);

Its not possible to call malloc to allocate memory for reg_confirm since reg_confirm is not a pointer. Your compiler should have produced either an error or a warning about that.

>>if (reg_confirm == NULL)
reg_confirm will never ever be NULL because it is not a pointer.

>>if (reg_confirm == "0")
You can't compare two character arrays like that. You have to call strcmp(), like this: if( strcmp(reg_confirm,"0") == 0)

thank you it worked fine, but now I get this warning:

warning C4715: 'IsRegistered': not all control paths return a value

what's that?

It means that there is a possibility that an condition or a loop statement flow results in a path without a return value

i.e. function runs and is expected to return a value but there is a possibility that it wont and thus create an application error...

all the compiler is telling you is to clean up and ensure you ALWAYS have a return :)

If you dont need any data returned... try declaring the function as a "void" or simply returning a 0 (numeric types), ""(text types), true(bool) etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.