Hi

My problem reqs a simulation code ( *.exe), which shd read the inputs from a file ( *.in) and after calculations , write the results to an output file ( *.out) .The names of the input and output files are hardcoded.

I shd be able to execute my sim code in batch mode and generate the output file. All this in C++.

Cld u please help me?

Thanks

You will probably get more help if you are more specific in what your question is and show effort of having worked on the problem yourself.

Alright,
I do not have problems with coding or the algo.
What I have to do is integrate the .exe with another software (isight), and this .exe shd read from a .in and generate a .out. I shd also be able to run this in batch mode.

For instance,
I have 2 inputs ... length and width in .in file

The .exe calculates the area and generates the output to a .out file

I'll have to integrate all three to isight and run an optimisation process, which I can manage on my own

I need help with the way to go abt reading from a .in file in a .c sim code and generate output to a .out file.

Just the procedure will be of great help or any links if possible.

Donno if I am in the right place

Tell me what kinda code you'll require... file handling is one way I cannot go abt doing this. Figured that much.

Thanks neways

shd? abt? What do these acronyms stand for???

>>file handling is one way I cannot go abt doing this

The only other way I know of is to redirect the input and output on the command line.

c:> myprogram < infile.in > outfile.out

That will redirect the file's contents to stdin just as if you typed the information on the keyboard, and redirect stdout to a file instead of displaying it on a console screen.

But I don't know why you can't just use FILE and associated C file handline functions to read the input file and write the output file.

shd? abt? What do these acronyms stand for???

"shd" is should

And
"abt" is about

Thanks a bunch.

What I mean by running in batch mode...
At the prompt, if my file name is test.exe , on typing the file name, the output file should be generated.
Now, test.exe is created after I run my test.c file.

Is file handline fns the only way to do this?

Here is a code:

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
    char ch1[50]="The length is : ";char ch2[50]="The width is : ";
    float l=8.0; float w=6.0;float a,p;
    char ch3[50]="The area is : ";char ch4[50]="The perimeter is : ";
    float temp1,temp2;

    ofstream outfile("newone.in");

    outfile<<ch1<<l<<endl<<ch2<<w;
    outfile.close();
    ifstream infile("newone.in");
    ofstream outf("newone.out");
    infile.getline(ch1,50);
    infile>>l;temp1=l;
    infile.getline(ch2,50);
    infile>>w;temp2=w;

    a=l*w;
    p=2*(l+w);
    outf<<ch3<<a<<endl;
    outf<<ch4<<p<<endl;
    infile.close();outf.close();

}

What will a .exe of this do every time I run it?

In another software, I am giving it permission to replace the values of l and w in my input file with its own randomly generated values, calculate new area and perimeter, and write it in the output file... this runs in a loop until I optimise my area. Now, after it replaces the values in the input file, it uses the .exe to do the new calculations and carry on for every run.

Doubts:
When, it runs the .exe, does it re-initialise the values of l and w?
What does running the .exe do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.