I want to keep entering a character till a '*' is entered and change the case of the character. The code I have written is
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
char character;
char con_char;
while(1)
{
printf("Enter a character:");
scanf("%c",&character);
printf("ASCII value of %c is %d\n", character, character);
if (character=='*')
{
printf("The program terminates\n");
exit(0);
}
else if (character>='a' && character<='z')
{
con_char = toupper(character);
printf("%c\t\t%c\n", character, con_char);
}
else if (character>='A' && character<='Z')
{
con_char = tolower(character);
printf("%c\t\t%c\n", character, con_char);
}
else
{
con_char=character;
printf("%c\t\t%c\n", character, con_char);
}
}
return 0;
}
The program works well but only for the format of the output. The line "Enter a character" is displayed in the output two times for a single input. I am not able to understand the reason. Please help. Output:
Enter a character:f ASCII value of f is 102 f F Enter a character:ASCII value of is 10
Enter a character: