0

What is the problem with this average word lenth code coach code?

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main() { char str[100]; gets(str); int x; x = strlen(str); int i,ans,l,min,n; float avg,s,m; int count=0; for(i=0;i<x;i++) { if(str[i] == 32) { count = count + 1; } } avg =((float)(x-count)/(float)(count+1)); m = (int)avg; s = avg - m; //printf("%f",s); if(s >= 0.0000000) n = ceil(avg); else if(s==0.000000) n = (int)avg; else n = floor(avg); printf("%d",n); return 0; }

24th Apr 2022, 2:26 PM
NERD 2 NERD
1 Respuesta
+ 1
By calculating the number of word characters as the difference of the total string length and the number of spaces, you are not ignoring punctuation, as is asked for in the exercise. By the way, the gets() function is deprecated and should not be used. A better alternative is fgets(), for example.
24th Apr 2022, 5:47 PM
Shadow
Shadow - avatar