#include #include #include #include #include struct NODE //define a structure { char *line; struct NODE *next; }; void prin_list (NODE *first,FILE *fout) //func. that prints list { struct NODE *ptr; //pointer to structure NODE for (ptr=first ; ptr!=NULL ; ptr=ptr->next) { fputs(ptr->line,fout); } } int address (NODE *help) { struct NODE *prt; prt=help->next; if (prt!=NULL) address(prt); printf("%s \n",help->line); return (0); } struct NODE* input(FILE *fin) { struct NODE *first; struct NODE *node ; int v; char res[1026]; //reservation of memory for char first=NULL ; while (1) { node =(struct NODE *) calloc (1,sizeof(NODE)); if(fgets(res,1024,fin)==NULL) return (first); res[1025]=0; node->line=(char*)calloc(strlen(res)+1,sizeof(char)); strcpy(node->line,res); node->next=NULL; if (first==NULL) first=node; else{ node->next=first; first=node; } } return(first); } int main () { char file1[]="test1.txt",file2[]="test2.txt";//test1.txt-file for reading FILE* fout; //test2.txt-output file FILE* fin; clrscr(); //clear screen struct NODE *first; //first it's pointer to structure NODE fin=fopen(file1,"r"); //fin it's pointer to begining of file test1.txt if(fin ==NULL) { printf("Can't open source file!"); return (0); } fout=fopen(file2,"r+"); if(fout==NULL) { printf("Can not write to file !"); return(0); } first=input(fin); prin_list(first,fout); fclose(fout); fclose(fin); return (0); }