0% found this document useful (0 votes)
27 views2 pages

C Program for Text Case Conversion

The document is a C program that provides a simple menu for text manipulation, allowing the user to convert input text to uppercase, lowercase, or switch between the two. It prompts the user for a choice and processes the input string accordingly. However, the program contains several issues, such as improper handling of the menu variable and the use of deprecated functions like 'gets'.

Uploaded by

Heart yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

C Program for Text Case Conversion

The document is a C program that provides a simple menu for text manipulation, allowing the user to convert input text to uppercase, lowercase, or switch between the two. It prompts the user for a choice and processes the input string accordingly. However, the program contains several issues, such as improper handling of the menu variable and the use of deprecated functions like 'gets'.

Uploaded by

Heart yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
#define UP_TO 150
int main(){

char kata[UP_TO];
char *k = kata;
int *menu, i;
printf("1. Uppercase\n2. Lowercase\n3. Switching\n4. Keluar\nPilihan : ");
scanf("%d",&menu);
fflush(stdin);

//for(i>=1;i<=3;i++){
//printf("Masukkan kata: ");
//}
//gets(kata);

//menu == 1;
switch((int)menu)
{
case 1:
printf("Masukkan kata: ");
gets(kata);
while(*k)
{
*k = (*k >= 'a' && *k <= 'z') ? *k-32 : *k;
k++;
}

printf("%s",kata);

return ;

//menu == 2;
case 2:
printf("Masukkan kata: ");
gets(kata);
while(*k)
{
*k = (*k >= 'A' && *k <= 'Z') ? *k+32 : *k;
k++;
}

printf("%s",kata);

return ;

case 3:
printf("Masukkan kata: ");
gets(kata);
for(int k = 0; k<strlen(kata); k++){
if (kata[k] >= 'A' && kata[k] <='Z')
printf(" %c", kata[k] + 32);
else if (kata[k] >= 'a' && kata[k] <= 'z')
printf("%c", kata[k] - 32);
}
return;
default:
printf("You Were Exited");

}
}

You might also like