Pagini recente » Cod sursa (job #612450) | Cod sursa (job #1587474) | Cod sursa (job #1815211) | Cod sursa (job #819965) | Cod sursa (job #770363)
Cod sursa(job #770363)
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
int main()
{
FILE *f = fopen("text.in","rt");
if (!f) return 0;
FILE *g = fopen("text.out","wt");
if (!g) {
fclose(f);
return 0;
}
char *sir = (char *)calloc(1000000,sizeof(char));
if (!sir) {
fclose(f);
fclose(g);
return 0;
}
char *temp = (char*)calloc(50,sizeof(char));
if (!temp) {
fclose(f);
fclose(g);
free(sir);
}
int k = 0;
int suma = 0;
fgets(sir,1000000,f);
temp = strtok(sir,"-,.;!~ ?");
while (temp)
{
k++;
suma += strlen(temp);
temp = strtok(NULL,"-,.;!~ ?");
}
float media = floor((suma-1)/(k-1));
fprintf(g,"%i",(int)media);
free(sir);
free(temp);
fclose(f);
fclose(g);
return 0;
}