0% found this document useful (0 votes)
18 views

Code

The document contains code for a C program that manages a Netflix-like subscription service. It includes functions for creating a new account, updating an existing account, deleting an account, and a main menu function to call the other functions.

Uploaded by

wiam97
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Code

The document contains code for a C program that manages a Netflix-like subscription service. It includes functions for creating a new account, updating an existing account, deleting an account, and a main menu function to call the other functions.

Uploaded by

wiam97
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>
#include<stdlib.h>
#include<windows.h>
#include <stdbool.h>
#include<conio.h>
int i,j;
int main_exit;
void menu();
void close();
struct date{
int month,day,year;

};
struct {

char first_name[60];
char last_name[60];
char email[100];
int acc_no;
struct date dob;
struct date birth;

}add,upd,rem,check;

void fordelay(int j)
{ int i,k;
for(i=0;i<j;i++)
k=i;
}

void new_acc()

{
int choice;
FILE *ptr;

ptr=fopen("record.txt","a+");
email:
system("cls");
printf("\t\t\t==== Subsciption ====");
printf("\n\n\nEnter your email");
scanf("%s",add.email);

while(fscanf(ptr,"%s %s %s
%d/%d/%d\n",add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year)
!=EOF)
{
if (check.email==add.email)
{printf("User already in use!");
fordelay(1000000000);
goto email;

}
add.acc_no=check.acc_no;
printf("\n\n\nEnter your first name");
scanf("%s",&add.first_name);
printf("\n\n\nEnter your last name");
scanf("%s",&add.last_name);
printf("\nEnter the date of birth(mm/dd/yyyy):");
scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&add.dob.year);
fprintf(ptr,"%s %s %d/%d/%d
\n",add.first_name,add.last_name,add.dob.month,add.dob.day,add.dob.year);

fclose(ptr);
printf("\nUser created successfully!");
add_invalid:
printf("\n\n\n\t\tEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
system("cls");
if (main_exit==1)
menu();
else if(main_exit==0)
close();
else
{
printf("\nInvalid!\a");
goto add_invalid;
}
}
void edit(void)
{
int choice,test=0;
FILE *old,*newrec;
old=fopen("record.txt","r");
newrec=fopen("new.txt","w");

printf("\nEnter your email:");


scanf("%s",&upd.email);
while(fscanf(old,"%s %s %s %d/%d/%d %d
",&add.email,add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year
)!=EOF)
{
if (add.email==upd.email)
{ test=1;
printf("\nWhich information do you want to change?\n1.EMAIL\n2.First
Name\n3.Last Name\n.4.The date of birth \n Enter your choice(1 , 2 , 3 or 4):");
scanf("%d",&choice);
system("cls");
if(choice==1)
{printf("Enter the new Email Adresse:");
scanf("%s",upd.email);
fprintf(newrec,"%s %s %d/%d/%d
\n",add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year);
system("cls");
printf("Changes saved!");
}
else if(choice==2)
{
printf("Enter the new First Name:");
scanf("%s",upd.first_name);
fprintf(newrec,"%s %s %d/%d/%d
\n",add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year);
system("cls");
printf("Changes saved!");
}

else if(choice==3)
{
printf("Enter the new Last Name:");
scanf("%s",upd.last_name);
fprintf(newrec,"%s %s %d/%d/%d
\n",add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year);
system("cls");
printf("Changes saved!");
}
else if(choice==4)
{
printf("Enter the new Date of Birth:");
scanf("%d\%d\%d",&upd.birth);
fprintf(newrec,"%s %s %d/%d/%d
\n",add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year);
system("cls");
printf("Changes saved!");
}

else
fprintf(newrec,"%s %s %s %d/%d/%d
\n",add.email,add.first_name,add.last_name,add.dob.month,add.dob.day,add.dob.year);
}
fclose(old);
fclose(newrec);
remove("record.txt");
rename("new.txt","record.txt");

if(test!=1)
{ system("cls");
printf("\nRecord not found!!\a\a\a");
edit_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to
exit:");
scanf("%d",&main_exit);
system("cls");
if (main_exit==1)

menu();
else if (main_exit==2)
close();
else if(main_exit==0)
edit();
else
{printf("\nInvalid!\a");
goto edit_invalid;}
}
else
{printf("\n\n\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
system("cls");
if (main_exit==1)
menu();
else
close();
}
}

void erase(void)
{
FILE *old,*newrec;
int test=0;
old=fopen("record.txt","r");
newrec=fopen("new.txt","w");
printf("Enter your Mail:");
scanf("%s",rem.email);
while (fscanf(old,"%s %s %s %d/%d/%d %d
",&add.email,add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year
)!=EOF)
{
if(add.email!=rem.email)
fprintf(newrec,"%s %s %s %d/%d/%d %d
",&add.email,add.first_name,add.last_name,&add.dob.month,&add.dob.day,&add.dob.year
);

else
{test++;
printf("\nUser deleted successfully!\n");
}
}
fclose(old);
fclose(newrec);
remove("record.txt");
rename("new.txt","record.txt");
if(test==0)
{
printf("\nUser not found!!\a\a\a");
erase_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to
exit:");
scanf("%d",&main_exit);

if (main_exit==1)
menu();
else if (main_exit==2)
close();
else if(main_exit==0)
erase();
else
{printf("\nInvalid!\a");
goto erase_invalid;}
}
else
{printf("\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
system("cls");
if (main_exit==1)
menu();
else
close();
}

}
void menu(void)
{ int choice;
system("cls");
system("color 7");
printf("\n\n\t\t\t Welcome To Netflix");
printf("\n\n\n\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO THE MAIN MENU
\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
printf("\n\n\t\t[1] Create a new account\n\t\t[2] Update information of
existing account\n\t\t[3] End Subscription\n\t\t[4] Exit\n\n\n\t\t Enter your
choice:");
scanf("%d",&choice);

system("cls");
switch(choice)
{
case 1:new_acc();
break;
case 2:edit();
break;
case 3:erase();
break;
case 4 :close();
break;
}

}
}
int main(void){
menu();
return 0;
}

You might also like