![]() |
|
#1
|
|||
|
|||
multiple file creation with fopen?Hello,
I'm trying to create several files (well actually 64 files) with incrementally with fopen. So, there will be result1 to result64. Is it possible to do it? Somehow, my program just got a funny char after the "result" file. I know one way to do it is to pass 64 arg to the file. Any suggestion would be appreciated. The program: CPP / C++ / C Code:
Last edited by LuciWiz : 01-Feb-2005 at 15:16.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
|
Quote:
You could try something like this to generate the file names: CPP / C++ / C Code:
Here are some of the problems with your method (other than the typographical errors where you used "file_real" instead of "file_result" in a couple of places): CPP / C++ / C Code:
It initializes the contents to: Quote:
Now, as you go through the loop, you replace result[6] with integer values from 1 throgh 64. Problems: 1. Many of these are not printing characters (a security feature?, since you can't easily discover their real name from the command line). 2. String functions (including printf() with %s format specifiers) need to have a sequence of chars terminated by a byte whose value is zero. The example that I gave lets you use the sprintf() function to convert the decimal numbers to their ascii (printable) digit representations: '1', '2', etc. Note that the length of the file name string can be as long as 8 characters, so the array must have length of at least 9 chars (to hold the terminating zero as well as the printable characters). I made it 10, just in case we ever want to have file names up to "result999". Regards, Dave |
|
#3
|
|||
|
|||
|
That was quick. It fixed the problem.
Thank you very much Dave! Regards, |
|
#4
|
|||
|
|||
|
Question:
Is there any limit that fopen can create files in MS DOS? I know that in one MS DOS directory you can only have 512 files. Any ideas why my program stop creating files after 445 files [(64x7) - 3]? Thank you. |
|
#5
|
|||
|
|||
|
Quote:
I don't know (and don't have any way to run any tests). Sorry. Regards, Dave |
|
#6
|
|||
|
|||
Re: multiple file creation with fopen?Quote:
I've tried the code in my program, but failed to do so. Appreciate if you could help me figure-out the problem in my code. Below are the details: 1. I'm trying to open several files named desc1.txt, desc2.txt, ... descn.txt using fopen. 2. Perform tokenization on the contents. 3. Save the tokenized words in the new files named tokword1.txt, tokword2.txt,... tokwordn.txt. CPP / C++ / C Code:
I've managed to perform the process using one single file, but failed when involved multiple files. Please help me. --- Ifa Last edited by cable_guy_67 : 14-Aug-2006 at 08:47.
Reason: Please surround your C code with [cpp] ... [/cpp]
|
|
#7
|
|||
|
|||
Re: multiple file creation with fopen?Quote:
After using fopen, are you using fclose on the FILE*? In DOS, there is a perscribed number of file handles available to the shell. You can modify this by increasing the FILES=nnn in your CONFIG.SYS file. If you are running a "DOS session" from something like Windows, then you need to modify your DOS emulation environment appropriately. I don't know how you're going about writing your code, but I thought that I'd offer a quick hack for you to review as something to consider. CPP / C++ / C Code:
Output: Code:
Note that I appended some zeros in front of the resultNNN so that they would list better. The reason that I created the array of file pointers is so that someone could later access them and write to them (other than Hello, World!) and free them without fear. Obviously, one can easily create two file pointer arrays for the input (to strtok) and the output (tokens) as per ifa's comments. It would then be very easy to write a tokenizing routine that tosses the tokens found in the input file into the output file. The signature of such a function would look something like: CPP / C++ / C Code:
:davis: |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 09-Mar-2004 23:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The