Tuesday, July 14, 2009

How can I create multiple output text file in C using turbo C?

I have a text file containing number of lines (not fixed). I want to write a programme which will create separate text file containing each line. How to do this using C in Turbo C. Anybody please help me and please tell it in detail.

How can I create multiple output text file in C using turbo C?
Use the below code as a reference......





#include "stdio.h"


#include "stdlib.h"























void main( )


{


FILE *fp;


char c;


int i=1;


fp = fopen("TENLINES.TXT", "r"); // Open the file to be read





if (fp == NULL) printf("File doesn't exist\n");


else {





// perform the loop until EOF


while(!feof(fp)) {





// Read a single line.....


if(fgets(str, 126, fp)) {


printf("%s", str);


//createfile(" Call create file function from here....


................


..................








}





}











}


fclose(fp);


}








void createfile(char* filename,char* content)


{


FILE *fpwrite;





int index;


fpwrite = fopen(filename,"w"); /* open for writing */


strcpy(stuff,content);


for (index = 1; index %26lt;= 10; index++)


fprintf(fpwrite,"%s Line number %d\n", stuff, index);


fclose(fpwrite); /* close the file before ending program */


}
Reply:http://www.thescripts.com/forum/thread49...





hope this will help


Cheers:)


No comments:

Post a Comment