Hey, I have several warnings I've been trying to get rid of, but to no avail. Should I be concerned with them? The program still runs fine.
a2.c: In function ‘main’:
a2.c:69: warning: implicit declaration of function ‘index’
a2.c:69: warning: assignment makes pointer from integer without a cast
a2.c:84: warning: control reaches end of non-void function
Here is my code.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int wordcount( char words[])
{
int j=0 , wcnt = 0, lenght;
j=strlen(words)-1;
while( strchr(" \t", words[j]) != 0 ) { words[j]=0 ; j-- ; }
j=0 ;
while( strchr(" \t", words[j]) != 0 ) j++;
words=words+j;
lenght = strlen(words) ;
for(j=0; j<=lenght; j++ )
if( strchr(" \t", words[j]) != 0 ) {
while( words[j+1]==' ' || words[j+1]=='\t' ) j++ ; wcnt++ ; }
/* At the EOF strchr() returns as if it matched ! */
return(wcnt);
}
int sylcount( char * words )
{
int i , j , sylc=0, length=strlen(words);
char * vowels="AEIOUYaeiouy";
for(j=0 ; j<=length ; j++){
i=j;
while( j<= length && strchr(vowels, words[j]) != 0 ) j++ ;
if( 1<j-i ){ sylc++ ; i=j; }
}
return(sylc);
}
int sentencecount( char * sentence)
{
int j , sencnt = 0, lenght = strlen(sentence);
char *sentenders = ".;:?!" ;
for(j=0; j<=lenght; j++ )
if( strchr(sentenders, sentence[j]) != 0 ) sencnt++;
/* At the EOF strchr() returns as if it matched ! */
return(sencnt);
}
int main()
{
char buf[1048576] , * i , * j ;
i=buf;
while( fgets(i, 1048576, stdin) != 0 )
{
if ( ( j=index(i,'\n') ) != 0 ) *j=' ';
i=i+strlen(i);
}
printf("\n\n%s\n\n", buf);
printf("Number of words: %d\n", wordcount(buf));
printf("Number of sylables: %d\n", sylcount(buf));
printf("Number of sentences: %d\n", sentencecount(buf));
}