Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct{
  5.     char *scelte;
  6.     int num_scelte;
  7. }livello;
  8. int princ_molt(int pos,livello *val,int n,char *sol,int count,FILE *fout);
  9. int main(int argc, const char * argv[]) {
  10.     FILE *fin,*fout;
  11.     livello *val;
  12.     char *sol,stringa[4];
  13.     int i,num;
  14.    
  15.     if((fin=fopen("file1.txt","r"))==NULL){
  16.         printf("errore apertura file1\n");
  17.         return -1;
  18.     }
  19.     if((fout=fopen("file2.txt","w"))==NULL){
  20.         printf("errore apertura file2\n");
  21.         return -2;
  22.     }
  23.     fscanf(fin,"%d",&num);
  24.     val=malloc(num *sizeof(livello));
  25.     sol=malloc(num *sizeof(char));
  26.    
  27.     for(i=0;i<num;i++){
  28.         fscanf(fin,"%s",stringa);
  29.         val[i].num_scelte=strlen(stringa);
  30.         val[i].scelte=malloc(val[i].num_scelte *sizeof(char));
  31.        
  32.     }
  33.  
  34.     return 0;
  35. }
  36.  
  37. int princ_molt(int pos,livello *val,int n,char *sol,int count,FILE *fout){
  38.     int i;
  39.     if(pos>=n){
  40.         for(i=0;i<n;i++)
  41.             fprintf(fout,"%c ",sol[i]);
  42.         printf("\n");
  43.         return count +1;
  44.        
  45.     }
  46.     for(i=0;i<val[pos].num_scelte;i++){
  47.         sol[pos]=val[pos].scelte[i];
  48.         count=princ_molt(pos+1,val,n,sol,count,fout);
  49.     }
  50.     return count;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement