Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  sss
Language: C/C++
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    FILE *f;
    int a,i,c;
    int celkom=0;
    int cislo=0;
    int *euro;
    char b;
    double priemer;
     if((f=fopen("kluc.txt","r"))==NULL){
         printf("Subor kluc.txt sa nepodarilo otvorit\n");
         return 1;
     }
     
     euro=(int*)malloc(sizeof(int));
     while((c=getc(f))!=EOF){
                              ungetc(c,f);
                              
                              
                              if ((c >= 'a' && c <= 'z')||(c >= 'A' && c <= 'Z')){          //co ja viem ked textovy subor moze mat len male pismena tak 
                                    fscanf(f,"%c",&b);                                      //daj tam toto if (c >= 'a' && c <= 'z') ale ked mozu tam byt aj velke
                                    continue;                                               //tak to nechaj tak ako to je....
                                     
                                    }
                              
                              if (c >= '0' && c <= '9'){
                              fscanf(f,"%d",&a);
                              euro[cislo]=a;
                              cislo++;
                              continue;   
                              }

for(i=0;i<cislo;i++){
                    
                    celkom=celkom+euro[i];
                    }


priemer=celkom/cislo;

printf("%.2f\n",priemer);                 //ked moze byt len cele cislo hore prepises priemer na int a sem namiest %.2f das %d
                                          //to %.2f bude vypisovat vysledok na 2 desatinne miesta

system("PAUSE");                                                                              
return 0;
}}
          
Comments: