Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  lola
Language: C/C++
Code:
#include <stdio.h>
#include <string.h>

typedef struct kind{ char nome[20],cognome[20];}kind;
kind alunno;

FILE *fp,*fp1;

char path[50]="Alunni.txt";

int i;


int main(){
     

fp=fopen(path,"wb");
for(i=0;i<2;i++)
{
printf("Inserire Nome: ");
gets(alunno.nome);
printf("Inserire Cognome: ");
gets(alunno.cognome);

fwrite(&alunno,sizeof(kind),1,fp);

}

fclose(fp);
char txt[]=".txt";
fp=fopen(path,"rb");
while(fread(&alunno,sizeof(kind),1,fp))
{
char p2[50]=".";
p2[0]=alunno.nome[0];
strcat(p2,txt);

fp1=fopen(p2,"ab");

fwrite(&alunno,sizeof(kind),1,fp1);
fclose(fp1);
}
fclose(fp);



     return 0;
}
          
          
          
          
          
          
Comments: