extern关键字使用,输入字符串,输一字符,字符串中所有该字符被删除

mac2024-10-27  44

// DeleteCharacterUseExtern #include <stdio.h> void main() { extern void enter_string(char str[]); extern void delete_character(char str[], char ch); extern void print_string(char str[]); char c; char str[80]; printf("Please enter a string:\n"); enter_string(str); printf("Please enter the charater which you want to delete:\n"); scanf_s("%c", &c, sizeof(c)); delete_character(str, c); print_string(str); } #include <stdio.h> void enter_string(char str[80]) { //printf("%d", sizeof(str)); gets_s(str,80); //这里sizeof(str)=4 } void delete_character(char str[], char ch) { int i, j; for (i = j = 0; str[i] != '\0'; i++) { if (str[i] != ch) { str[j++] = str[i]; } } str[j] = '\0'; } #include <stdio.h> void print_string(char str[]) { printf("%s\n", str); } //extern关键字可调用文件外函数及常量
最新回复(0)