#include<stdio.h>
#include<stdlib.h>
void write(int num)
{
FILE *fp;
fp=fopen("storeNum.txt","w");
fprintf(fp,"%d",num);
fclose(fp);
printf("succesfully stored");
printf("\nQuitting the program....");
}
void display(void)
{
system("clear");
int num3;
FILE *fp;
fp=fopen("storeNum.txt","r");
fscanf(fp,"%d",&num3);
printf("Displaying numbee\n");
printf("%d\n",num3);
fclose(fp);
printf("Quitting the program....");
}
void check(int num2)
{ int num4;
int x;
FILE *fp;
fp=fopen("storeNum.txt","r");
fscanf(fp,"%d",&num4);
if(num2==num4)
{
printf("It already exist\n");
printf("Quitting the program....");
fclose(fp);
}
else
{
printf("Not exist \nPress\n1.to save\n ");
scanf("%d",&x);
system("clear");
if(x==1)
{
fp=fopen("storeNum.txt","w");
fprintf(fp,"%d",num2);
fclose(fp);
printf("succesfully saved");
}
printf("Quitting the program....");
}
}
int main()
{
int numLo,numCheck,choice;
printf("Enter\n1.To store a number\n2.To display a number\n3.To check if that number is already stored\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
system("clear");
printf("Enter a number to store\t");
scanf("%d",&numLo);
write(numLo);
break;
case 2:
display();
break;
case 3:
system("clear");
printf("Enter a number to check\t");
scanf("%d",&numCheck);
check(numCheck);
break;
default :
printf("Quitting the program....");
break;
}
}
Comments
Post a Comment