The program scans a maximum of 10 chars from user and then offers you 4 options what you can do with that array. Options are:
- 0 = quit the program,
- 1 = prints whole array,
- 2 = count all the small letters,
- 3 = prints only the numbers,
- 4 = change the small letters with the big ones and via versa.
This is my homework for school, so the interface needs to be in Czech. I think that overall it's quite good but I want to improve!!
#include <stdio.h>
int main() {
int char_count = 10;
char input_chars[char_count];
int i = 0;
int applied_numb = 1;
int last_index;
int amount_small_char = 0;
int ascii_code;
printf("Zadejte maximalne 10 znaku" );
do {
printf(" \n Zadejte %d z %d: ", i, char_count);
input_chars[i] = getchar();
getchar();
i++;
if(i == char_count) {
printf("Zadali jste maximalni pocet znaku. \n");
}
} while(i < char_count && input_chars[i - 1] != '.' );
if(input_chars[i - 1] == '.')
{
// in case of last element is "." substract 2 from last index(because we used do while cycle (i++))
last_index = i - 2;
}
else
{
last_index = i - 1;
}
while (applied_numb != 0 && applied_numb <= 4 && applied_numb >= 0)
{
printf("Vyberte si co chcete s danymi cisli provest: \n 0) konec programu \n 1) vypis \n 2) pocet malych pismen \n 3) vypsat jen cislice \n 4) zmenit mala/velka pismena\n");
scanf ("%i", &applied_numb);
switch (applied_numb)
{
case 0:
printf ("KONEC PROGRAMU, SEE YOU SOON :) ");
break;
case 1:
printf("Vypis vaseho vstupuje: ");
for(i = 0; i <= last_index; i++)
{
printf(" %c",input_chars[i]);
}
break;
case 2:
for (i = 0; i <= last_index; i++)
{
ascii_code = (int)input_chars[i];
if (ascii_code >= 97 && ascii_code <= 122)
{
amount_small_char = amount_small_char + 1;
}
}
printf("Pocet malych pismen ve vasim vstupu je: %d", amount_small_char);
break;
case 3:
printf("Tyto cislice jsou ve vasem vstupu:");
for (i = 0; i <= last_index; i++)
{
ascii_code = (int)input_chars[i];
if (ascii_code >= 48 && ascii_code <= 57)
{
printf(" %c", input_chars[i]);
}
}
break;
case 4:
printf("Zmena na mala/velka pismena vypada takto:");
for (i = 0; i <= last_index; i++)
{
ascii_code = (int)input_chars[i];
if (ascii_code >= 97 && ascii_code <= 122)
{
ascii_code = ascii_code - 32;
printf(" %c", ascii_code);
}
else if(ascii_code >= 65 && ascii_code <= 90)
{
ascii_code = ascii_code + 32;
printf(" %c", ascii_code);
}
else if((ascii_code <= 64 && ascii_code >= 0) ||
(ascii_code >= 91 && ascii_code <= 96) ||
(ascii_code >= 123))
{
printf(" %c", input_chars[i]);
}
}
break;
}
printf("\n \n ------------------------------------- \n \n ");
}
return 0;
}