i want to break a large file into smaller files each of size 2KB.i want to give the file names as 1.txt,2.txt,3.txt etc how can i do this
i want to break a large file into smaller files each of size 2KB.i want to give the file names as 1.txt,2.txt,3.txt etc how can i do this
read in some of the file... then write out to a file... then read in more of the file... and write more... till you are done reading.
problem is how to name the files i have an index variable i want to create the files with the name as that of the contents of index variable
variable i=1;
char tempname[6];
read base file till end
read 2kb from file
tempname=strcat(inttostring(i)+".txt");
write to new file fopen(tempname,"w");
i++;
end read
Long time no C. I need to learn the language again.
Help a man when he is in trouble and he will remember you when he is in trouble again.
You learn in life when you lose.
Complex problems have simple, easy to understand wrong answers.
"A ship in the harbour is safe, but that's not what ships are built
for"
I do wish you would stick to one board for your questions
http://forums.devshed.com/c-programm...ng-370788.html
Fair enough asking on another board if one doesn't respond in a day or two, but to broadcast all over the place just makes it seem like you're trying to post "urgent" without actually saying so.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
My suggestion is to use sprintf to generate a new filename.
Note that snprintf and a dynamically allocated character array might be a better solution since snprintf returns the characters it would have printed if it had to truncate the buffer. Thus you can use it to size the string correctly, but I didn't want to drag dynamic memory into this.Code:int index = 1; /* this would be your index variable you were talking about */ char filename[256]; sprintf(filename, "%d%s", index, ".txt");
[edit]Oh neat... cross-posting.
Last edited by whiteflags; 07-24-2006 at 12:29 AM.