im working on an assignment for school, and i need to count the number of words, lines, and charcters that the user inputs untel they enter a EOF, but my program wont work for some reason, and i cant tell whats wrong.
Code:
#include <stdio.h>
#include <ctype.h>
#define NULL 0
main()
{
char buff[256];
int len, line_count=0, char_count=0, last_char_flag, index, word_count;
printf("Please Type some stuff, and hit ctrl+z to end\n");
do
{
if(gets(buff)==EOF)
break;
line_count++;
char_count=len;
len=strlen(buff);
}
while(1);
for(index=0; index<len; index++)
{
if(last_char_flag==0)
word_count++;
if(buff[index]!=' ')
word_count++;
if(buff[index]==' ')
last_char_flag=0;
else
last_char_flag=1;
}
printf("there are %d charcters\n %d lines\n and %n words\n", len, line_count, word_count);
}
int strlen(char able[])
{
int index=0;
while(able[index]!=NULL)
index++;
return(index);
}