Pagini recente » Cod sursa (job #3256226) | Cod sursa (job #661151) | 2014oni10 | Cod sursa (job #2424026) | Cod sursa (job #1334385)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10000
int calc(char* s);
int main()
{
FILE* in = fopen("text.in","r");
FILE* out = fopen("text.out","w");
char *s = (char*)malloc(sizeof(char)*max);
fgets(s,max,in);
printf("%s",s);
int c = calc(s);
fprintf(out,"%d",c);
return 0;
}
int calc(char* s){
int nrWords=0;
int length = 0;
char * tok = strtok(s," `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");
while(tok!=NULL){
length += strlen(tok);
nrWords++;
tok=strtok(NULL, " `~1234567890!{@#$%^&**()-}|\":+?=><,./;'[]\"");
}
return length/nrWords;
}