The ID no: in case1 should be not repeated..[e.g when ID:1 is enter and save in text file 1 is not allowed anymore to enter...]
please help me with my error to fix...
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip>
using namespace std;
main(){
FILE *ptr;
FILE *tptr;
char wb[100];
int idn, sidn,idFromFile;
int ch, xidn;
char menu;
bool exist;
system("cls");
cout<<"Menu\n\n";
cout<<"1. add\n";
cout<<"2. view\n";
cout<<"3. del\n";
cout<<"Choice: ";
cin>>ch;
switch (ch){
case 1:
{
ptr = fopen("add.txt", "a+");
if(ptr == NULL)
{
cout<<"\n\nFILE COULD NOT BE OPENED!";
}
else{
ifstream ViewLogin(ptr);
cout<<"\nID: ";
cin>>idn;
getline(ViewLogin, idnFromFile);
while(idn == idnFromFile)
{
cout<<"\nID EXIST!";
cout<<"\nID: ";
cin>>idn;
}
cout<<"\twebsite: "; cin>>wb;
fprintf(ptr,"%d\n%s\n", idn, wb);
fclose(ptr);
}
getch();
goto repeat;
}
case 2:
{
ptr = fopen("add.txt", "r");
if(ptr == NULL){
cout<<"\n\nFILE COULD NOT BE OPENED!";
}
else{
char xwb[100];
int xidn;
cout<<"Search ID: "; cin>>sidn;
while(!feof(ptr)){
fscanf(ptr,"%d%s\n", &idn, wb);
if(sidn == idn){
xidn = idn;
strcpy(xwb, wb);
}
else{
cout<<"ID NOT EXIST!";
}
}
cout<<"\nInfo\n";
cout<<"ID:"<<"\t"<<xidn<<endl;
cout<<"Website: "<<"\t\t"<<xwb<<endl;
fclose(ptr);
}
getch();
goto repeat;
}
case 3:
{
ptr = fopen("add.txt", "r");
int del;
if(ptr == NULL){
cout<<"\n\nFILE COULD NOT BE OPENED!";
}
else{
while(!feof(ptr))
{
fscanf(ptr,"%d%s\n", &idn, wb);
cout<<"Info\n";
cout<<"ID:"<<"\t\t\t"<<idn<<endl;
cout<<"website: "<<"\t\t"<<wb<<endl;
}
cout<<" delete all records? 1 - YES, 2 - NO\n";
cin>>del;
if(del == 1){
ptr = fopen("add.txt", "w");
if(ptr == NULL){
cout<<"\n\nFILE COULD NOT BE OPENED!";
}
else{
fprintf(ptr,"");
}
}
else if(del == 2){
goto repeat;
}
else{
cout<<"Wrong Input!";
goto repeat;
}
fclose(ptr);
}
getch();
goto repeat;
}
default:
{
cout<<"Wrong choice!";
getch();
goto repeat;
}}
repeat:
cout<<"\nReturn to Main Menu? [Y/N]";
cin>>menu;
if((menu == 'Y')||(menu == 'y')){
return main();
}
if((menu == 'N')||(menu == 'n')){
return 0;
}
getch();
}
[edit]Code block added, HTML characters encoded - OriginalGriff[/edit]
[edit]Clean Subject and Question body - johny10151981[/edit]