Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Studente : Scia Massimiliano
- Classe : 3IC
- Data : 12/04/12 15:51
- Nome del file : rubrica disordinata, file di testo
- */
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <cctype>
- #include <windows.h>
- #include <fstream>
- #include <time.h>
- #include <string>
- #include <stdio.h>
- #define N 100
- using namespace std;
- void bg_col(){
- system("color 71");
- }//bg_col
- void end(void){
- fflush(stdin);
- cout<<"\n\nPremere Invio per continuare.";
- getchar();
- }//end
- void ins_address(char* fileName, char* mode){
- char contact[N];
- FILE* myFile;
- myFile=fopen(fileName,mode);
- cout<<"\nInsert contacts as the example (surname , name , number)";
- cout<<"\nEx...'Cavani , Edinson , 098727621'";
- cout<<"\nPress ' . ' to end\n";
- fflush(stdin);
- cin.get(contact,N,'\n');
- fflush(stdin);
- while(strcmp(contact,".") != 0){
- fputs(contact, myFile);
- fputc('\n', myFile);
- fflush(stdin);
- cin.get(contact,N,'\n');
- fflush(stdin);
- }//while
- fclose(myFile);
- }//ins_address
- bool is_created(char* fileName){
- if(fopen(fileName,"r")==NULL)
- return false;
- else
- return true;
- }//is_created
- int main(){
- char fileName[N];
- char mode[N];
- bg_col();
- fflush(stdin);
- cout<<"\nInsert filename (with .txt extension):";
- cout<<"\nEx. myFile.txt\n- ";
- cin.get(fileName,N,'\n');
- fflush(stdin);
- bool b=is_created(fileName);
- char c,cc;
- if(b){
- cout<<"\n\nThe file already exist, overwrite? (s / n)";
- cout<<"\n\n o = overwrite, q = write in queue, c = create new";
- cout<<"\n- ";
- do{
- cin>>c;
- if(c!='o' && c!='q' && c!='c')
- cout<<"\nChoice error\n- ";
- }//do
- while(c!='o' && c!='q' && c!='c');
- if(c=='o')
- ins_address(fileName, "w");
- else if(c=='q')
- ins_address(fileName, "a");
- else{
- strcat(fileName,"_1");
- ins_address(fileName, "w");
- }//else
- }//if
- else{
- cout<<"\nThe file searched is not available";
- cout<<"\n\nCan i create a new one? (s/n)";
- cout<<"\n\n y = yes, n = no";
- cout<<"\n\n- ";
- do{
- cin>>cc;
- if(cc!='y' && cc!='n')
- cout<<"\nChoice error\n- ";
- }//do
- while(cc!='y' && cc!='n');
- if(cc=='y')
- ins_address(fileName, "w");
- else
- cout<<"\n\nAloha! :)";
- }//else
- end();
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement