How can i make it so it doesn't output the same word more than once? And to make it go back to the entering input until they press CTRL+Z as the input?
Code:
#include <stdio.h>
/* This function takes all the characters and makes them UPPERCASE */
int LowUpp(int ch)
{
if ( 'a' <= ch && ch <= 'z' )
{
return (ch + 'A' - 'a');
}
else
{
return ch;
}
}
char c;
int main()
{
int LowUpp(int ch);
char word[23];
char userstring[1024];
char Array[1024][100];
int wordcount = 0;
int charcount = 0;
int wordnumb = 0;
int i = 0;
int j = 0;
int row = 0;
int column = 0;
printf("Word & Character Counter\n\n\n");
printf("Enter your input ([CTRL+Z] To Quit): ");
if(fgets(userstring, 1024, stdin) == NULL)
return 0;
printf("\n\nWord Count ");
printf("Word ");
printf("Character Count \n");
printf("---------------------------------------------------------------\n");
while(userstring[i] != '\0')
{
if((userstring[i] != ' ') && (userstring[i] != '\n') && (userstring[i] != '\t'))
{
charcount++;
word[j++] = LowUpp(userstring[i]);
}
else
{
wordnumb++;
word[j] = '\0';
Array[row][column] = word[i];
if(charcount < 8)
printf("%d\t\t\t%s\t\t\t%d\n", wordnumb, word, charcount);
else
printf("%d\t\t\t%s\t%d\n", wordnumb, word, charcount);
charcount = 0;
wordcount++;
j = 0;
}
i++;
}
printf("---------------------------------------------------------------\n");
printf("Total Words: %d\n\n", wordcount);
return 0;
}