I did try to fill the new array with '\0', but it still doesn't work. The new string is located at the beginningof the array, but the older string is still right after the new one....
What is going on? What did I do wrong this time?
Code:
# include <stdio.h>
int main()
{
char again = 'y';
char inputstring[112] = "\0";
char *inputptr;
int i = 0;
int count_vow = 0;
int count_cons = 0;
int count_white = 0;
int count_punct = 0;
int non_counted = 0;
int tot_wh_sp_ct = 0;
inputptr = inputstring;
do
{
{
printf("Enter an English text. Use at least one character and no more than 111 characters, including white spaces.\n");
gets(inputstring);
printf("The text you entered was:\n");
printf("%s", inputstring);
for (i = 0; i<=111; i++)
{
switch(inputstring[i])
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U': count_vow++;
default: non_counted++;
}
switch(inputstring[i])
{
case 'b':
case 'B':
case 'c':
case 'C':
case 'd':
case 'D':
case 'f':
case 'F':
case 'g':
case 'G':
case 'h':
case 'H':
case 'j':
case 'J':
case 'k':
case 'K':
case 'l':
case 'L':
case 'm':
case 'M':
case 'n':
case 'N':
case 'p':
case 'P':
case 'q':
case 'Q':
case 'r':
case 'R':
case 's':
case 'S':
case 't':
case 'T':
case 'v':
case 'V':
case 'x':
case 'X':
case 'y':
case 'Y':
case 'z':
case 'Z': count_cons++;
default: non_counted++;
}
switch(inputstring[i])
{
case ' ':
case '\t': count_white++;
default: non_counted++;
}
switch(inputstring[i])
{
case '.':
case ';':
case ',':
case '!':
case '?': count_punct++;
default: non_counted++;
}
}
tot_wh_sp_ct = count_white + 1;
printf("\nand it contained %d consonants, %d vowels, %d white spaces, %d punctuation marks.",count_cons, count_vow, tot_wh_sp_ct, count_punct);
}
for (i=0; i<=111; i++)
{
inputstring[i] = '\0';
}
printf("\nWould you like to enter another text?");
again = getchar();
while ( getchar() != '\n' )
continue;
}
while (again == 'y' || again =='Y');
return 0;
}