// Usage: ./client <fileIn> <fileOut> <fileOut2> <heapSize> <rowCount> <rowLength> int main (int argc, char* argv[]) { char* nameFileIn = argv[1]; char* nameFileOut = argv[2]; char* nameFileOut2 = argv[3]; char** page; FILE* fpI,* fpO; int nr; heap_t* heap; strArray_t* save; int D = atoi(argv[4]), N = atoi(argv[5]), M = atoi(argv[6]); printf("input file: %s\noutput file: %s\noutput file 2: %s\n", nameFileIn, nameFileOut, nameFileOut2); printf("D: %d - N: %d - M: %d\n", D, N, M); heap = heapCreate(D); save = strArrayInit(heap, 0); /* inizializza a vuoto */ page = (char**)heapAlloc(heap, N * sizeof(char*)); fpI = fopen(nameFileIn, "r"); fpO = fopen(nameFileOut, "w"); if (page == NULL || fpI == NULL || fpO == NULL) { printf("Errore in allocazione memoria o apertura file\n"); exit(1); } while ((nr = leggiPagina(heap, page, fpI, N)) > 0) { ordinaPagina(page, nr); scriviPagina(page, fpO, nr); filtraeLiberaPagina(heap, page, nr, save, M); } fclose(fpI); fclose(fpO); heapFree(heap, page); fpO = fopen(nameFileOut2, "w"); if (fpO == NULL) { printf("Errore in apertura file\n"); exit(1); } strArraySort(save); strArrayPrint(save, fpO); fclose(fpO); strArrayFree(heap, save); heapDestroy(heap); return 0; }
int main (int argc, char *argv[]) { char *nameFileIn = argv[1]; char *nameFileOut = argv[2]; char *nameFileOut2 = argv[3]; char **page; FILE *fpI, *fpO; int i, nr; strArray_t *save = strArrayInit(0); /* inizializza a vuoto */ int D=atoi(argv[4]), N=atoi(argv[5]), M=atoi(argv[6]); printf("input file: %s - output file: %s\n", nameFileIn, nameFileOut); printf("input file: %s - output file: %s output file 2\n", nameFileIn, nameFileOut, nameFileOut2); printf("D: %d - N: %d - M: %d\n", D, N, M); page = (char **) malloc (N * sizeof(char *)); fpI = fopen (nameFileIn, "r"); fpO = fopen (nameFileOut, "w"); if (page==NULL || fpI==NULL || fpO==NULL) { printf("errore in allocazione memoria o apertura file\n"); exit (1); } while ((nr = leggiPagina(page,fpI,N)) > 0) { ordinaPagina(page,nr); scriviPagina(page,fpO,nr); filtraeLiberaPagina(page,nr,save,M); } fclose(fpI); fclose(fpO); free(page); fpO = fopen (nameFileOut2, "w"); if (fpO==NULL) { printf("errore in apertura file\n"); exit (1); } strArraySort(save); strArrayPrint(save,fpO); fclose(fpO); strArrayFree(save); }