大写提取函数
編寫一個程序,輸入一個字符串input,編寫函數(shù)foo,將input傳入foo的參數(shù)str。foo函數(shù)要在堆中創(chuàng)建一個適當(dāng)長度的字符串,將str字符串中的大寫字符依次復(fù)制到堆中的字符串,并將該字符串返回給main。main函數(shù)輸出返回的字符串后,在堆中銷毀該字符串。
#include<stdio.h> #include<stdlib.h> char* foo(char* str); int main() {char input[1000],*str,*temp;//printf("15151");gets(input);temp=str=foo(input);while (*str != '\0') {printf("%c", *str);str++;}free(temp);return 0; } char* foo(char* str) {char* temp;int cnt = 0;temp = (char*)malloc(1000 * sizeof(char));for ( cnt = 0; (*str) != '\0'; str++) {if ((*str) >= 'A' && (*str) <= 'Z') {temp[cnt] = *str;cnt++;}}temp[cnt] = '\0';return temp;}總結(jié)
- 上一篇: L1-005 考试座位号
- 下一篇: L1-011 A-B (20 分)(c语