#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{ /* the error start here*/ ifstream ViewLogin(ptr); cout<<"\nID: "; cin>>idn; //cin.ignore(); //xidn = ptr.idn; getline(ViewLogin, idnFromFile); while(idn == idnFromFile) { cout<<"\nID EXIST!"; cout<<"\nID: "; cin>>idn; } //if( 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; } //case 4: 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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)