满意答案
s彩虹u
2013.07.02
采纳率:52% 等级:13
已帮助:9561人
/* 1. */ #include #include char* ReadFile(const char* psz) { FILE* fp = fopen(psz, "r"); if( NULL == fp ) return NULL; fseek(fp, 0, SEEK_END); int nLen = ftell(fp); char* pszBuff = (char*)malloc(nLen + 1); fseek(fp, 0, SEEK_SET); int nSize = fread(pszBuff, 1, nLen, fp); pszBuff[nSize] = 0; fclose(fp); return pszBuff; } void Sort(const char* psz) { FILE* fp = fopen("New.txt", "w"); while( *psz ) { if( ((*psz >= '0') && (*psz <= '9')) || ((*psz >= 'A') && (*psz <= 'F')) || ((*psz >= 'a') && (*psz <= 'f')) ) { printf("%c", *psz); psz++; continue; } fprintf(fp, "%c", *psz); psz++; } } int main() { char* pszBuff = ReadFile("Old.txt"); if( NULL == pszBuff ) return 0; Sort(pszBuff); free(pszBuff); printf("\n"); } /* 2. */ #include #include void input(int array[], int n) { for(int i = 0; i < n; i++) { scanf("%d", &array[i]); } } int find(int array[], int n, int x) { int count = 0; for(int i = 0; i < n; i++) { if( x == array[i] ) { count++; } } return count; } main() { int arr[5]; printf("waiting for array input:\n"); input(arr, 5); int x; printf("please enter the target :\n"); scanf("%d", &x); int count = find(arr, 5, x); if( 0 == count ) { printf("Not find!\n"); return 0; } printf("the key %d count:\n", count); }
00分享举报