Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define ESITI 3
- #define MAXNOME 64
- int conta_righe(char nomefile[]);
- void leggi(char** *matrice, char nomefile[], int N);
- void espandi(char** matrice, char* combinazione, int i, int j, int N);
- main()
- {
- char sistema[MAXNOME+1];
- int partite, i, j;
- char** pronostici;
- char* combinazione;
- printf("File input? ");
- scanf("%s", sistema);
- partite = conta_righe(sistema);
- leggi(&pronostici, sistema, partite);
- combinazione = (char*)malloc(partite*sizeof(char));
- espandi(pronostici, combinazione, 0, 0, partite);
- system("PAUSE");
- return 0;
- }
- int conta_righe(char nomefile[])
- {
- FILE *input;
- char car;
- int righe = 0;
- input = fopen(nomefile, "r");
- if (input != NULL)
- {
- while (fscanf(input, "%c", &car)!=EOF)
- {
- if (car == '\n')
- righe++;
- }
- fclose(input);
- }
- else
- {
- printf("File non trovato. ");
- system("PAUSE");
- exit(EXIT_FAILURE);
- }
- return righe;
- }
- void leggi(char** *matrice, char nomefile[], int N)
- {
- char **tmpmatr, riga[ESITI+1];
- FILE *input;
- int i, j;
- input = fopen(nomefile, "r");
- if (input != NULL)
- {
- tmpmatr = (char**) malloc(N*sizeof(char*));
- for (i = 0; i < N; i++)
- {
- tmpmatr[i] = (char*) malloc((ESITI+1)*sizeof(char));
- fscanf(input, "%s", tmpmatr[i]);
- }
- fclose(input);
- *matrice = tmpmatr;
- }
- else
- {
- printf("Errore in lettura. ");
- system("PAUSE");
- exit(EXIT_FAILURE);
- }
- }
- void espandi(char** matrice, char* combinazione, int i, int j, int N)
- {
- j = 0;
- if (i == N)
- {
- combinazione[i] = '\0';
- printf("%s\n", combinazione);
- }
- else
- {
- while (matrice[i][j]!='\0')
- {
- combinazione[i] = matrice[i][j];
- espandi(matrice, combinazione, i+1, j, N);
- j++;
- }
- i--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment