I need to make a journal (basically a program to read and write to files), with a login system, so I need to save the login information into a file. I dont know what the username and password would be since the user puts that, and I want to store that variable into a file. Also I was wondering how I could access that value after. Like say I store the variable username into a file, and I end the program, then I run it again, how would I be able to access the username so I can verify that the user that started the program is entering the right username. This is my final project for my Grade 12 course, and we don't have a proper comp sci teacher, so everything I know is self taught. So I'm not that comfortable with pointers, and pretty new to files. If you guys have any links which you recommend for me to learn these two topics from, it'll be much appreciated. Thanks for reading. The code that I got so far:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000
void signUp (char username [SIZE], char password [SIZE], char name [SIZE], int age)
{
char null;
printf("\nSign Up Procedure: \n");
scanf("%c", &null);
printf("Please enter your username: ");
gets(username);
printf("Please enter a password: ");
gets(password);
printf("Enter your full name: ");
gets(name);
printf("Enter your age: ");
scanf("%d", &age);
printf("\nUsername: %s, Password: %s, Full Name: %s, Age: %d", username, password, name, age);
}
void logIn(char username [SIZE], char password [SIZE])
{
}
int main()
{
printf("1. Log In\n"); // Enter 1 for logging in
printf("2. Sign Up\n"); // Enter 2 for signing up
int choice;
printf("Choice: ");
scanf("%d", &choice);
char username [SIZE];
char password [SIZE];
char name [SIZE];
int age;
int keepGoing = 0;
while (keepGoing == 0)
{
switch (choice)
{
case (1):
logIn (username, password);
keepGoing = 1;
break;
case (2):
signUp (username, password, name, age);
keepGoing = 1;
break;
default:
printf("Please enter a choice from the given options");
keepGoing = 0;
break;
}
}
FILE * pfile;
pfile = fopen("Planner.txt", "w");
fputs("Hello World", pfile);
fputs("%s", username);
fclose(pfile);
return 0;
}