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;
}
}
int main()
{
int LowUpp(int ch);
char word[50];
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("Enter your input: ");
if(fgets(userstring, 1024, stdin) == NULL)
return 0;
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];
printf("%d %s %d \n", wordnumb, word, charcount);
charcount = 0;
wordcount++;
j = 0;
}
i++;
}
printf("There were %d words and %d characters.\n", wordcount, charcount);
return 1;
}
How do I put that in an array so it looks like this ?
Code:
Total Words: 6
Word Count Word Character Count
-------------------------------------------------------
1 SEA 3
2 TO 2
3 SHINING 7
4 C 1
5 HELLO 5
6 WORLD 5
-------------------------------------------------------