Hi all.

Could anyone please put comments on each command that Ancient Dragon posted? It's just to be sure what each of them means.

I'm having trouble compiling this (it's not what Ancient Dragon wrote!!):

//blabla

    char OutFile[100];

    FILE* fp;
    sprintf(OutFile,"wind%d", date);
    fp = fopen(OutFile,"w");
    OutFile << "Longitude\tLatitude\tDirection\tVelocity\n";//here appears an error!!
//blabla

Maybe there is another way of writing information into the output file, but I'm used to writing in c++...not c.

thanks for your time.

Recommended Answers

All 13 Replies

Hi all.

Could anyone please put comments on each command that Ancient Dragon posted? It's just to be sure what each of them means.

I'm having trouble compiling this:

//blabla

    char OutFile[100];

    FILE* fp;
    sprintf(OutFile,"wind%d", date);
    fp = fopen(OutFile,"w");
    OutFile << "Longitude\tLatitude\tDirection\tVelocity\n";//here appears an error!!
//blabla

Maybe there is another way of writing information into the output file.

thanks!

I didn't write that. The line you marked with error is C++ code, not C code. You can't put c++ code in a c program.

Maybe there is another way of writing information into the output file.

yeah... that would be the Standard C Library command, fprintf()

not the C++ specific command you're trying to blindly force into the C program.

Sorry.

I don't write c programs I only know a bit of c++.

Do you know how to do what the first post asks, but in c++ language?

>>Do you know how to do what the first post asks, but in c++ language?

Yes I do. Do you know how? (hint: first learn to ask the right questions.) If you know c++ then the conversion should be pretty easy for you.

delete lines 3 to 7, and replace them with ofstream object.

I've tried so many things that i'm geting confused. :P

I had my c++ program but then i just got all messed up with c and c++.
my problem is this,

Imagine you have a .txt file with information about the weather.
for example:

blabla
blabla
-20090420 06 hrs sea level
data (several lines)
-20090420 06 hrs 1000 feet
again data
-20090420 12 hrs sea level
data
etc
etc


I know how to put the date and time, etc into strings or integers. What i don't know is how to put them in the name of the output files, example:
-20090420_06_0.txt
-20090420_06_1000.txt
-20090420_12_0.txt

So that each file contains the specific data for a specific date and time, on a determined hight.

you're being great Ancient, thanksfor your patience.

Here's what i had first:

//code
    ofstream OutFile;
    OutFile.open("Wind.txt", ios::out);

    for(k=0;k<18;k++){
         InpFile >> word;
         OutFile << longitude << "\t";
         latitude=30.0+k*1.0;
         OutFile << latitude << "\t";

         ConvertToInt=atoi(word.c_str());
         velocity=ConvertToInt%1000;
         direction=ConvertToInt/1000;
         OutFile << direction<< "\t" << velocity<< "\n";
   }

You can't put c++ code in a c program.

Apparently I can and so can annyone. I did solve my problem, here it is:

ifstream InpFile;
    char OutFile[100];
//code
                FILE* fp;
                sprintf(OutFile,"Wind%d_%d_%d.txt", date, time, level);
                fp = fopen(OutFile,"w");
                fprintf(fp, "Longitude,Latitude,Direction,Velocity\n");

                for(i=0;i<25;i++){
                    longitude=-20.0+i*1.0;
                    for(k=0;k<18;k++){
                        InpFile >> word;
                        fprintf(fp, "%f,", longitude);
                        latitude=30.0+k*1.0;
                        fprintf(fp, "%f," , latitude);

                        ConvertToInt=atoi(word.c_str());
                        velocity=ConvertToInt%1000;
                        direction=ConvertToInt/1000;
                        fprintf(fp, "%d,%d\n" , direction, velocity);
                    }
                fclose(fp);
//code

This is the proof. I use c++ language to open the reading file and I use c language to write the ouput files!

Annyway thanks again.

commented: you must learn to read, before you can write. -1
commented: That's just ridiculous, a C compiler will never compile C++ code :) +2

>>Apparently I can and so can annyone. I did solve my problem, here it is:

NO YOU DIDN'T. You put C code in a C++ program, not the other way around. C++ supports most C, but C supports nothing from C++.

>>This is the proof.
You proved nothing.

ahah. he doesn't know C at all and barely knows C++, and yet he just performed the impossible -- with proof! call the ACM journals! prepare the honorary PhDs!

seriously though, where DO these people come from?

commented: This makes me laugh, good post ! +2

>>Apparently I can and so can annyone. I did solve my problem, here it is:

NO YOU DIDN'T. You put C code in a C++ program, not the other way around. C++ supports most C, but C supports nothing from C++.

>>This is the proof.
You proved nothing.

lol.

I believe you. I guess I misunderstood you. maybe I can't put c++ into c. But I can put c into c++. that's the only thing I prooved. :D
Although I prooved it only to myself or so it seems.

ahah. he doesn't know C at all and barely knows C++, and yet he just performed the impossible -- with proof! call the ACM journals! prepare the honorary PhDs!

seriously though, where DO these people come from?

I come from the same place you did my friend. Stardust.

If I knew as much as you do about c and c++ I wouldn't need to ask you for help. When I say "this is the proof", it means check it out people see if it's correct and if not tell me where it's wrong or what it's wrong. It doesn't mean "In your face!!" But I guess the place you come from you just hear that a lot. sorry about that.

whatever, dude. you made the assertion, not me.

proof (prf)
n.
1. The evidence or argument that compels the mind to accept an assertion as true.

so, next time, when you want to say :

"check it out people see if it's correct and if not tell me where it's wrong"

how about saying:

"check it out people see if it's correct and if not tell me where it's wrong"

instead of

"here is the proof"

you see, words have meaning. they're funny like that.

>you see, words have meaning. they're funny like that.
Haha :icon_razz: I found that post hilarious.

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.