Pagini recente » Cod sursa (job #1661917) | Cod sursa (job #3202444) | Cod sursa (job #3212339) | Cod sursa (job #2272935) | Cod sursa (job #824673)
Cod sursa(job #824673)
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(){
FILE *fp, *fr;
char buf[1024];
size_t nread;
int i, spaces = 0, media, n, total = 0, totalSpaces = 0, removedElement = 0, totalWords = 0;
char word[1024];
fp = fopen("text.in","r");
fr = fopen("text.out", "w");
if(fp == NULL || fr == NULL){
printf("could not open one of the files!");
exit(0);
}
while ((nread = fread(buf, 1, sizeof buf, fp)) > 0){
fwrite(buf, 1, nread, stdout);
total = total + nread;
}
for(i = 0; i < total; i++){
if(buf[i] == 32){
spaces++;
}
if((buf[i] < 65 || (buf[i] > 90 && buf[i] < 97) || buf[i] > 122) && buf[i] != 32){
removedElement++;
}
}
totalSpaces = spaces + 1;
totalWords = (total - spaces) - removedElement;
media = totalWords / totalSpaces;
fprintf(fr, "%d", media);
fclose(fp);
fclose(fr);
return 0;
}