Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140613 Exercise 01 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/06/13 pm.06:24 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- void main()
- {
- fflush(stdin);
- system("cls");
- char input[3][10] = {EOF};
- int counter_of_input = 0;
- for(int i = 0; i < 3; i++)
- {
- counter_of_input++;
- if(i != 0)
- {
- printf("\n");
- }
- printf("Enter a string %1d: ", counter_of_input);
- fflush(stdin);
- scanf("%[^\n]", input[i]);
- printf("Do you want to enter next string (Y/N): ", counter_of_input);
- char select = EOF;
- fflush(stdin);
- scanf("%c", &select);
- if((select == 'Y') || (select == 'y'))
- {
- continue;
- }
- else
- {
- break;
- }
- }
- printf("\nAnswer 1\n======================================\n");
- for(int i = 0; i < counter_of_input; i++)
- {
- printf("String %1d is: %s.\n", i + 1, input[i]);
- }
- printf("\nAnswer 2\n=======================================\n");
- int counter_of_number = 0;
- char number_of_input[3][10] = {EOF};
- int tmpN = 0;
- for(int i = 0; i < counter_of_input; i++)
- {
- tmpN = 0;
- for(int j = 0; j < strlen(input[i]); j++)
- {
- if(isdigit(input[i][j]))
- {
- counter_of_number++;
- number_of_input[i][tmpN] = ((int)input[i][j]) - 48;
- tmpN++;
- }
- }
- }
- printf("Number's number of times in all string is: %d.\n", counter_of_number);
- for(int i = 0; i < counter_of_input; i++)
- {
- printf("String %1d number is: ", i + 1);
- for(int j = 0; j < strlen(number_of_input[i]); j++)
- {
- switch(j)
- {
- case 0:
- printf("%d", number_of_input[i][j]);
- break;
- default:
- printf(", %d", number_of_input[i][j]);
- break;
- }
- }
- printf(".\n");
- }
- printf("\nAnswer 3\n=======================================\n");
- char letter_of_input[2][30] = {EOF}; //0 is upper, 1 is lower.
- int tmpUpper = 0, tmpLower = 0;
- for(int i = 0; i < counter_of_input; i++)
- {
- tmpN = 0;
- for(int j = 0; j < strlen(input[i]); j++)
- {
- if(!isdigit(input[i][j]))
- {
- if(isupper(input[i][j]))
- {
- letter_of_input[0][tmpUpper] = input[i][j];
- tmpUpper++;
- }
- else if(islower(input[i][j]))
- {
- letter_of_input[1][tmpLower] = input[i][j];
- tmpLower++;
- }
- }
- }
- }
- for(int i = 0; i < 2; i++)
- {
- switch(i)
- {
- case 0:
- printf("In all string, capital letter have: ");
- break;
- case 1:
- printf("In all string, small letter have: ");
- break;
- }
- for(int j = 0; j < strlen(letter_of_input[i]); j++)
- {
- switch(j)
- {
- case 0:
- printf("%c", letter_of_input[i][j]);
- break;
- default:
- printf(", %c", letter_of_input[i][j]);
- break;
- }
- }
- printf(".\n");
- }
- printf("\nAnswer 4\n=======================================\n");
- char ascii_of_input[30] = {EOF};
- int tmpLetter = 0;
- for(int i = 0; i < counter_of_input; i++)
- {
- for(int j = 0; j < strlen(input[i]); j++)
- {
- ascii_of_input[tmpLetter] = input[i][j];
- tmpLetter++;
- }
- }
- printf("In all input string, letter's ASCII descending order of: ");
- int typesetting = 0;
- for(int i = 255; i >= 0; i--)
- {
- for(int j = 0; j < strlen(ascii_of_input); j++)
- {
- if((int)ascii_of_input[j] == i)
- {
- switch(typesetting)
- {
- case 0:
- printf("%c", ascii_of_input[j]);
- typesetting++;
- break;
- default:
- printf(", %c", ascii_of_input[j]);
- break;
- }
- }
- }
- }
- printf(".\n\n");
- printf("Do you want to restart this program(0/1): ");
- while(1)
- {
- fflush(stdin);
- char select_of_restart = 0;
- scanf("%c", &select_of_restart);
- if(isdigit(select_of_restart))
- {
- switch((int)select_of_restart - 48)
- {
- case 0:
- exit(1);
- break;
- case 1:
- main();
- break;
- default:
- printf("Press 0 to exit, 1 to restart: ");
- break;
- }
- }
- else
- {
- printf("Press 0 to exit, 1 to restart: ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment