Problem with File

U

utab

Dear All,

I have file like:

$ -----------------------
$ file management section
$ -----------------------
$ -------------------------
$ executive control section
$ -------------------------
SOL 103
TIME 100000
CEND
$ --------------------
$ case control section
$ --------------------
ECHO = NONE
METHOD = 1
DISP = ALL
PARAM,COUPMASS,1
PARAM,OLDSEQ,-1
$ -----------------
$ bulk data section
$ -----------------
BEGIN BULK
$
PARAM AUTOSPC YES
PARAM GRDPNT 0
$
EIGRL 1 1. 10000. 20 0
MASS
$ property definitions
PBARL 1 1 BAR
0.4 0.4
$ material definitions
MAT1 1 21.E+10 0.3 7800.
$ grid point definitions
GRID 1 0 2.5 2.5 0. 0 123456
GRID 2 0 12.5 2.5 0. 0 345
GRID 3 0 12.5 12.5 0. 0 345
GRID 4 0 2.5 2.5 0. 0 345
$ element definitions
CBAR 1 1 1 2 0. 1. 0.
CBAR 2 1 2 3 0. 1. 0.
CBAR 3 1 3 4 0. 1. 0.
CBAR 4 1 4 5 0. 1. 0.
CBAR 5 1 5 6 0. 1. 0.
CBAR 6 1 6 7 0. 1. 0.
CBAR 7 1 7 8 0. 1. 0.
CBAR 8 1 8 9 0. 1. 0.
CBAR 9 1 9 10 0. 1. 0.
CBAR 10 1 10 11 0. 1. 0.
ENDDATA


I am trying to write a different information in the portion between

$ grid point definitions

and

$ element definitions

When I run the program, it hangs, Could you please help me overcome
this. Could you also specify some good tutorials on the combination of
GDB+DDD if you know some. My code is below:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
char linein[80];
fstream inFile("fo.dat",ios::in | ios::eek:ut );

if (!inFile) // Always test file open
{
cerr << "Error opening input file" << endl;
return -1;
}
while(inFile.getline(linein,80)){
if(strcmp(linein,"$ grid point definitions") == 0){
cout << "found" << endl;
inFile.ignore();
string x="try";
while(inFile.get() != '$'){ // read until the other block
inFile.seekg(23,ios::cur);
inFile << "deneme";
inFile.getline(linein,80);
inFile.ignore();
}
}
}
inFile.close();
return 0;
}
 
V

Victor Bazarov

utab said:
I have file like:

[blah]
$ grid point definitions
GRID 1 0 2.5 2.5 0. 0 123456
GRID 2 0 12.5 2.5 0. 0 345
GRID 3 0 12.5 12.5 0. 0 345
GRID 4 0 2.5 2.5 0. 0 345
$ element definitions
[blah]

I am trying to write a different information in the portion between

$ grid point definitions

and

$ element definitions

When I run the program, it hangs, Could you please help me overcome
this.

See the explanation below.
> Could you also specify some good tutorials on the combination of
GDB+DDD if you know some.

You need to ask about those in the newsgroup for your platform.

If you need to learn how to "change information in a text file", read the
archives. It's been discussed numerous times. You cannot simply
"replace" something in a text file "in-place". The gist: you need to
write unchanged portions to a different file, then new information, then
other unchanged portions. Then rename the old file (to back it up), then
rename the new file to have the name of the old file before the operation.
> My code is below:

[...]

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top