So, i'm just practicing on my C programing skills and i wrote a program that gets a password and check it, if the password is correct so it call a MessageBox and show a message to user then it checks for existing file if the files is not existing it uses CreateFile and need to write some string inside.
from some reason it's not working and i can't understand why.
here is the code:
#include <stdio.h>
#include <Windows.h>
#include <string.h>
#pragma warning(disable:4996)
int main()
{
char SecretPass[7] = "Az1236";
char Userinput[7];
int ResultCMP;
printf_s("Insert Pass:");
fgets(Userinput, 7, stdin);
ResultCMP = strcmp(SecretPass, &Userinput);
if (ResultCMP == 0)
{
int msg = MessageBox(NULL, "You Got In", "Wow", MB_ICONEXCLAMATION);
if (msg == IDOK)
{
printf_s("Great! \n");
char *szFileName = "C:\\Users\\shai\\Desktop\\Create\\kilroy.txt";
FILE *fp = fopen(szFileName, "r");
if (fp == NULL) {
HANDLE h = CreateFileA(szFileName, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
FILE *fp;
fp = fopen(szFileName, "w+");
fprintf(fp, "testtest");
puts("Done");
fclose(fp);
}
else
{
printf("File exists!\n");
getchar();
return 0;
}
}
else
{
printf_s("wrong pass!");
getchar();
}
}
}