fstream problem

new to c++,i have written a code to write a data ,

  FILE *file;
  file = fopen(fileName,"r");
  ofstream wfile(writefileName);
  wfile << "#VRML V2.0 utf8"<<endl;
  wfile << "#Wilson"<<endl;
   d = 0;
   while ((str = fgets(line,LINESIZE,file)) && !feof(file))
      if (!strcmp(token,"v")) {

        wfile << "#" << endl;
      cout<<"wfile write ... "<<endl;

but after it works,there r only
#VRML V2.0 utf8
in this data

what's happened?
and how can i solve it?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

>>what's happened?

You are not verifying that the input file was opened successfully:

file = fopen(fileName,"r");

if (!file) {

  cout << "FAILED to open " << fileName << endl;

So, it might just be that the file could not be found.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
btw, it is in general not a good idea to mix C style IO with C++ - why not using an 'ifstream' for the input?
iuxAuthor Commented:
i have written
if (!strcmp(token,"v")) {
    cout<<"v read..."
it works,so i think it opens seccessfully

and i found with sscanf and fscanf much easier than get() and getline for input and ofstream << for output(code easier han fwrite)

its really the problem cause mix?

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

maybe if you put str= fgets(line,LINESIZE,file) outside the while condition
iuxAuthor Commented:
thx,but i think its necessary for this code
>    if (!strcmp(token,"v")) {
Why "token"? May be "str"?

And keep in mind that the strcmp() does case-dependent comparison.
It mean that the "#" will be written to out-file when you read exactly "v" from in-file only.
iuxAuthor Commented:
i have defined before
char token[1000];

and i have written
if (!strcmp(token,"v")) {
    cout<<"v read..."

it works when compiler
so i thinks it has read "v" successfully
Does the:

cout<<"wfile write ... "<<endl;

output show up on stdout?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.