int compare (const void * a, const void * b) { return ( *(int*)b - *(int*)a ); }
typedef struct _MY_DATA { char lpField1[10]; char lpField2[8]; } MY_DATA;
MY_DATA lpFileContent[200]; i = 0; while (fscanf(lpFile, "%s %s", lpFileContent[i]->lpField1, lpFileContent[i]->lpField2) == 2) i++;
qsort(lpFileContent, i, sizeof(MY_DATA), compare);
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionint compare (const void * a, const void * b) { MY_DATA* dataA; MY_DATA* dataB; dataA = (MY_DATA*)a; dataB = (MY_DATA*)b; return (compte(dataB->lpField2) - compte(dataA->lpField2)); }
previousCount = -1; fileIndex = 1; lpFile = NULL; while (fscanf(%s %s, blabla) == 2) { currentCount = compte(blabla) if (currentCount != previousCount) { if (lpFile) fclose(lpFile); sprintf(fileName, "essai%d.txt", fileIndex); lpFile = fopen(fileName, "w"); fileIndex++; previousCount = currentCount; } fprintf("%s %s\n", blabla); }
FILE* lpFile; char lpFileName[20]; for (i = 0; i <=6; i++) { sprintf(lpFileName, "essai%d.txt", fileIndex); lpFile = fopen(lpFileName, "r"); if (lpFile) { ... fclose(lpFile); } }
int compte(ch) char ch[32]; { int *tabPos; int i,p=0,k=0,m; tabPos = (int *) malloc(sizeof(int)); for(i=0; i < strlen(ch) ; i++) { if (ch[i] == '1') k=k+1; else { tabPos[p]=i; p++; } } printf("\\\\\\\\\\\\\\***\n"); for(m=0;m<p;m++) printf("%d : ",tabPos[m]); printf("///////////\n"); free(tabPos); return (k); }