Help me with C++ program that writes data every 100 timestep

Status
Not open for further replies.

fatma1000

Banned
Joined
Apr 30, 2006
Messages
147
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
eygpt
Activity points
0
help9 c++

i need to write my data in my program every 100 time step in fifferent file
so i need to open 10 files and write in the first at t=100 then write in the scond at t=200 and so on
how come?

please help to do this .

regards
 

help9 c++

mmm...doesn't sound to difficult.
Step 1) open files...all 10 for writing
Step 2) do calculations and run a counter.
Step 3) use if or a case command
Step 4)write to file according to if or case.
 

Re: help9 c++

i need sum thing to avoid openning 10 files because if i need to open 100 file
so please i need method to let program to creat files and write in it



regards
 

help9 c++

ok that opens the playing field.
must this be done in one shot or every time the prog runs, it most create a file?
 

Re: help9 c++

You can't opene more than N files, where N is OS dependent value. Other than that, just generate file name when trying to open the file like this:


char name[128];
FILE *fp;
int i = 0;



sprintf(name."%s%02d.bin". "name", i); /* now the name is name01.bin and we can open 100 files with name00 to name99 */
fp = fopen(name, "wb"); /* write over old file */

.....


Is this what you were looking for?

Added after 5 minutes:

Here is the small test program which will create 100 files:


#include <stdio.h>
#include <errno.h>

int main(void)
{
char name[128];
FILE *fp;
int i = 0, j;


for (i=0; i<100; i++)
{
sprintf(name,"%s%02d.bin", "name", i); /* now the name is name01.bin and we can open 100 files with name00 to name99 */
fp = fopen(name, "wb"); /* write over old file */
if (fp == NULL)
{
printf("Create file %s failed. Errno = %d\n", name, errno);
return errno;
}
fclose(fp);
}
return 0;
}
 

Re: help9 c++

so thanks ,
if i compute E over t from 0 to 15000 and i need to write E at t=1000 in one file and at t=2000 in scond file and so on how come ?

regards
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…