I call getchar in an inner loop.
Here's the full program:
Code:
#include <stdio.h>
int main(void)
{
int no_in_row, total, no_rows, c;
float average;
no_rows = 0;
total = 0;
while((c = getchar()) != EOF)
{
no_in_row = 0;
while(c != '\n')
{
c = getchar();
if(c != ' ')
no_in_row++;
} // Inner loop
no_rows++;
total = total + no_in_row;
} // Outer loop
printf("Total: %d, no_rows: %d\n", total, no_rows);
//printf("No in row %d\n", no_in_row);
average = (float)total / no_rows;
printf("Average characters in a row: %.2f\n", average);
return 0;
}