Mazamin

Numeri Stop File

Dec 13th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX_LEN 8
  4.  
  5. main(){
  6.     char numeri[10][MAX_LEN]={"zero", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove"}, temp[MAX_LEN];
  7.     FILE * fp;
  8.     int i, n=0, m=0;
  9.     ((fp=fopen("numeri.txt", "r"))!=NULL)?:(exit(0));
  10.     while(feof(fp)==0){
  11.         fscanf(fp, "%s", temp);
  12.         for(i=0;i<10;i++)
  13.             if((strcmp(numeri[i], temp))==0){
  14.                 m*=10;
  15.                 m+=i;
  16.             }
  17.             else if((strcmp("stop", temp))==0){
  18.                 n+=m;
  19.                 m=0;
  20.             }
  21.     }
  22.     printf("%d\n", n);
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment