Have you tried to compile it?
You will get some error message indicating which lines you should check:
if strcmp(passwordone,passwordtwo ==0)
That is obviously invalid C/C++ syntax. It must be
if (strcmp(passwordone,passwordtwo) == 0)
For this line the compiler complains about
password
being undeclared:
fprintf(fptr,"%s", password);
Should be obvious how to fix this.
The compiler might also complain about having no declaration for
strcmp()
(depends on the used compiler). Include
string.h which contains the declaration.
Finally, never use the
gets()
function. Use
fgets()
instead (but note that this will not remove the new line from the input so that you have to do it by code).
To fulfill the requirement of writing to the file only when the passwords match, perform the writing to the output file including the opening and closing in the corresponding
if
block at the end of your program.