Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #define SIZE 10000
- int dalipasva (char *t, const char *duma, int n)
- {
- for(int i=0; i<n; i++)
- {
- if(t[i]!=duma[i])return 0;
- }
- return 1;
- }
- char* Chetene (FILE *f,char *rez)
- {
- char u;
- int i;
- for(i=0; (u=fgetc(f))!=EOF; i++)
- {
- rez[i]=u;
- }
- rez[i+1]='\0';
- return rez;
- }
- int dalineeotime(char x)
- {
- if(x=='_')return 0;
- if(x>='a'&&x<='z')return 0;
- if(x>='A'&&x<='Z')return 0;
- if(x>='0'&&x<='9')return 0;
- return 1;
- }
- void ifelse(char *text,int dg,int gg,int &brif, int &brel)
- {
- for(int i=dg; i<=gg; i++)
- {
- if(dalipasva(&text[i],"if",2)&&dalineeotime(text[i-1])&&dalineeotime(text[i+2]))brif++;
- else if(dalipasva(&text[i],"else",4)&&dalineeotime(text[i-1])&&dalineeotime(text[i+4]))brel++;
- }
- }
- void razpredelenie(char* text,int &brkom, int &brif, int &brel)
- {
- int dg=0,i;
- for(i=0; text[i]!='\0'; i++)
- {
- if(dalipasva(&text[i],"//",2))
- {
- ifelse(text,dg,i-1,brif,brel);
- dg=i+2;
- }
- else
- {
- if(dalipasva(&text[i],"/*",2))
- {
- ifelse(text,dg,i-1,brif,brel);
- dg=i+2;
- }
- }
- }
- ifelse(text,dg,i-1,brif,brel); //obira posledniq nezavurshen interval
- }
- int main () {
- int mode;
- do {
- printf("1 - Reading program from file and Write final result on the input file name\n");
- printf("2 - Reading program from file and Printing result from Console\n");
- printf("3 - Reading program from Console and Writing final result from input file name \n");
- printf("4 - Readind program from Console and Printig result from Console\n");
- printf("5 - Exit\n");
- scanf("%d",&mode);
- FILE *f1,*f2;
- char masiv[SIZE],rez[SIZE];
- int brif=0,brel=0,brk=0;
- switch(mode){
- case 1:
- printf("Enter file name for Read: ");
- scanf("%s",masiv);
- f1=fopen(masiv,"r");
- printf("Enter file name for Write: ");
- scanf("%s",masiv);
- f2=fopen(masiv,"w");
- razpredelenie(Chetene(f1,rez),brk,brif,brel);
- fprintf(f2,"The if/else operators are ");
- sprintf(masiv,"%d",brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fprintf(f2,"The solo if operators are ");
- sprintf(masiv,"%d",brif-brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fclose(f1);
- fclose(f2);
- return 0;
- case 2:
- printf("Enter file name for Read: ");
- scanf("%s",masiv);
- f1=fopen(masiv,"r");
- f2=stdout;
- razpredelenie(Chetene(f1,rez),brk,brif,brel);
- fprintf(f2,"The if/else operators are ");
- sprintf(masiv,"%d",brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fprintf(f2,"The solo if operators are ");
- sprintf(masiv,"%d",brif-brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fclose(f1);
- fclose(f2);
- return 0;
- case 3:
- f1=stdin;
- printf("Enter file name for Write: ");
- scanf("%s",masiv);
- f2=fopen(masiv,"w");
- printf("You now is Read Mod forom Console \n Insert Contr + Z to Stop Reading \n");
- razpredelenie(Chetene(f1,rez),brk,brif,brel);
- fprintf(f2,"The if/else operators are ");
- sprintf(masiv,"%d",brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fprintf(f2,"The solo if operators are ");
- sprintf(masiv,"%d",brif-brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fclose(f1);
- fclose(f2);
- return 0;
- case 4:
- f1=stdin;
- f2=stdout;
- printf("You now is Read Mod forom Console \n Insert Contr + Z to Stop Reading \n");
- razpredelenie(Chetene(f1,rez),brk,brif,brel);
- fprintf(f2,"The if/else operators are ");
- sprintf(masiv,"%d",brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fprintf(f2,"The solo if operators are ");
- sprintf(masiv,"%d",brif-brel);
- fprintf(f2,masiv);
- fputc('\n',f2);
- fclose(f1);
- fclose(f2);
- return 0;
- break;
- case 5:
- break;
- default:
- printf("Wrong choise\n");
- break;
- }
- } while (mode != 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement