Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Studente : Scia Massimiliano
- Classe : 3IC
- Data : 13/05/12 18:25
- Nome del file : controlla vocali, lettere, numeri
- */
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <cctype>
- #include <windows.h>
- #include <fstream>
- #include <time.h>
- #include <stdio.h>
- #define N 100
- using namespace std;
- struct code{
- char c[N];
- };//struct
- void end(void){
- fflush(stdin);
- cout<<"\n\nPremere Invio per continuare.";
- getchar();
- }//end
- bool scrivi(char* nomefile){
- FILE* f;
- f=fopen(nomefile,"ab+");
- if(f==NULL)
- return false;
- int n;
- cout<<"\nQuanti codici vuoi inserire?\n- ";
- cin>>n;
- code cd;
- for(int i=0;i<n;i++){
- cout<<"\nCodice "<<i+1<<": ";
- fflush(stdin);
- cin.get(cd.c,N,'\n');
- fflush(stdin);
- fwrite(&cd,sizeof(code),1,f);
- }//for
- fclose(f);
- return true;
- }//scrivi
- bool controllo(char* nomefile, int a[]){
- FILE* f;
- f=fopen(nomefile,"rb");
- code cd;
- if(f==NULL)
- return false;
- for(int i=0;i<3;i++)
- a[i]=0;
- fread(&cd,sizeof(code),1,f);
- while(!feof(f)){
- for(int j=0;j<strlen(cd.c);j++){
- if(isalpha(cd.c[j])){
- a[0]++;
- if(tolower(cd.c[j])=='a' || tolower(cd.c[j])=='e' || tolower(cd.c[j])=='i' || tolower(cd.c[j])=='o' || tolower(cd.c[j])=='u')
- a[1]++;
- }//if
- if(isdigit(cd.c[j]))
- a[2]++;
- }//for
- fread(&cd,sizeof(code),1,f);
- }//while
- fclose(f);
- return true;
- }//controllo
- bool visualizza(char* nomefile, int a[]){
- FILE* f;
- f=fopen(nomefile,"rb");
- if(f==NULL)
- return 0;
- code cd;
- fread(&cd,sizeof(code),1,f);
- while(!feof(f)){
- cout<<"\n\nLettere: "<<a[0]<<"\nVocali: "<<a[1]<<"\nNumeri: "<<a[2];
- fread(&cd,sizeof(code),1,f);
- }//while
- fclose(f);
- return 1;
- }//visualize
- int main(){
- char nomefile[N];
- int a[N];
- cout<<"\nIl nome del file e`: ";
- fflush(stdin);
- cin.get(nomefile,N,'\n');
- fflush(stdin);
- bool s,c,v;
- s=scrivi(nomefile);
- c=controllo(nomefile,a);
- v=visualizza(nomefile,a);
- end();
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement