Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140603 Exam 13 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/06/03 am.11:40 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h> //字元測試函數庫
- //做轉換大小寫、字串中數字相乘之功能function
- void function(char *inputPtr);
- void main()
- {
- printf("Enter a string: ");
- char input[50] = {EOF};
- scanf("%[^\n]", input);
- function(input); //input 前不需加取址符號(&), 因陣列本身就代表一連串的指標
- }
- void function(char *inputPtr)
- {
- char output[50] = {EOF}; //Answer of string
- int number_multiply = 1; //Answer of number to multiply
- int counter_string = 0; //counter of string
- while(1)
- {
- //當字串讀取到結尾處時
- if(*inputPtr == '\0')
- {
- break;
- }
- else if(*inputPtr != '\0')
- {
- //islower = 判斷字元是否為小寫
- if(islower(*inputPtr))
- {
- //toupper = 將字元由小寫轉換為大寫
- output[counter_string] = toupper(*inputPtr);
- }
- //isupper = 判斷字元是否為大寫
- else if(isupper(*inputPtr))
- {
- //tolower = 將字元由大寫轉為小寫
- output[counter_string] = tolower(*inputPtr);
- }
- else
- {
- //其它狀況照常輸出, 如空格、數字等
- output[counter_string] = *inputPtr;
- }
- //add answer counter
- counter_string++;
- //isdigit = 判斷此字元是否為數字(0 - 9)
- if(isdigit(*inputPtr))
- {
- number_multiply *= (int)*inputPtr - 48;
- }
- //移至下個指標
- *inputPtr++;
- }
- }
- printf("Answer of string is: %s.\n", output);
- printf("Answer of number to multiply: %d.\n", number_multiply);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment