Thread: what does this mean

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    Unhappy what does this mean

    What does this error message mean: Warning: String literal converted to char* in formal argument title in call to DisplayStorms(char*, Storm**, int). In main for DisplayStorms I wrote DisplayStorms("First ten storms", List, 10) and DisplayStorms("Top ten storms", List, 10). The function's prototype is: void DisplayStorms( char* title, Storm* List[], int NStorms ). I dont' know what I'm doing wrong to get this error message.

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    a literal string is constant, so it's possible that it can't convert it to a variable

    int the prototype, try putting

    const char *

    instead of

    char *

    try it and tell me if it works

    Good luck

    Oskilian

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    Now my program is not working now. My program is supposed to print out the number of hurricanes being processed, the number of hurricanes that are category 3 or above, the first ten category 3 or above storms, and then a sorted list of the top ten storms. My I type in a.out, nothing gets printed. I think I did everything right. I'm just starting to learn about C++ and this is my first project that I have to do for class and it's due on Tuesday. My teacher didn't explain data structures too well and that's why more than 80% of the class is having problems with this project. Then my professor left for the week so I can't go to him to get any help and that's why I'm posting on the C++ board. Anyways I would like to thank you for helping me out and here's my code:

    // necessary library header files:
    #include<iostream.h>
    #include<fstream.h>
    #include<iomanip.h>
    #include<string.h>

    // global user-defined types:
    struct Storm {
    int beginDate;
    int duration;
    char name[15];
    int category;
    int wind;
    int pressure;
    };

    // function prototypes:
    int GetRecord( ifstream &input, int &y,int &m, int &d, int &h,
    int &s, char name[], int &wind, int &pres);
    Storm* GetStorm( ifstream& input );
    int SaffirSimpson( int w );
    void Sort( Storm* List[], int NStorms );
    void DisplayStorms( const char* title, Storm* List[], int NStorms );
    void PrintStorm( Storm* StormPointer );

    // Constants
    const int MAX_STORMS = 200;
    const float KnotsToMPH = 1.15;

    int main( void ) {
    Storm* List[MAX_STORMS];
    Storm* CurrentStorm; // storm returned by GetStorm
    int NStorms = 0; // number in aray List
    int Total = 0; // total number of storms in the input file

    // replace with interactive version
    ifstream input("HurricaneTestFile.Data");

    // while we have storms to process
    while( (CurrentStorm = GetStorm( input ) ) != NULL ) {
    ++Total;
    if( CurrentStorm->category < 3 )
    delete CurrentStorm;
    else
    List[NStorms++] = CurrentStorm;
    }

    input.close();

    cout << "Number of storms: " << Total << endl;
    cout << "Hurricanes with category 3 and above: " << NStorms << endl;
    DisplayStorms("First Ten Storms", List, 10 );

    Sort( List, NStorms);
    DisplayStorms("Top Ten Storms", List, 10 );

    }

    int GetRecord( ifstream &in, int &year, int &month, int &day, int &hour,
    int &seq, char name[], int &wind, int &pres ) {
    // reads one "record" from the input, and stores in reference arguments
    // returns 0 if end-of-file, 1 if record read

    float junk;

    if (!(in.eof())) {
    in >> year >> month >> day >> hour >> seq >> name
    >> junk >> junk >> wind >> pres;
    return 1;
    }

    return 0;
    }

    Storm* GetStorm( ifstream& in ) {
    // Build a Storm structure, and return the poointer
    // static is necesary to save the last record read for
    // the next storm.

    static int year = 0, month, day, hour, seq, wind, pressure;
    static char name[15];
    static status = 1;
    int current, cat;
    Storm* NewStorm; // we'll return this pointer to the new storm object
    double mph;
    // If the last storm caused end-of-file, we're done.(return NULL)
    if( status == 0 )
    return NULL;

    // If this is the first time this function is called,
    // then read first record.
    if( year == 0 )
    GetRecord(in, year, month, day, hour, seq, name, wind, pressure);

    // Make a storm object and initialize it with info from the current record
    NewStorm = new Storm;
    NewStorm->beginDate = (year * 1000) + (month * 100) + day;
    NewStorm->duration = hour;
    strcpy(NewStorm->name, name);
    NewStorm->wind = wind;
    NewStorm->pressure = pressure;

    current = seq;

    // Now, keep reading records as long as they go with this storm.
    // Watch out for end-of-file!
    status = GetRecord(in, year, month, day, hour, seq, name, wind, pressure);
    while((strcmp(NewStorm->name, name) == 0) && (status == 1)) {
    //update storm info:
    NewStorm->duration += 6;
    if(NewStorm->wind < wind)
    NewStorm->wind = wind;
    if(((pressure < NewStorm->pressure) && pressure != 0) || NewStorm->pressure == 0 )
    NewStorm->pressure = pressure;
    cat = SaffirSimpson(NewStorm->wind);
    if(cat > NewStorm->category)
    NewStorm->category = cat;
    //get next record
    GetRecord(in, year, month, day, hour, seq, name, wind, pressure);
    }

    // convert from knots to mph
    NewStorm->wind *= KnotsToMPH;

    // and return the pointer to the new storm object:
    return NewStorm;
    }

    void PrintStorm( Storm* ptr ) {
    // display one storm
    cout << ptr->beginDate << ptr->duration << ptr->name << ptr->category
    << ptr->wind << ptr->pressure << endl;

    return;
    }

    void DisplayStorms( const char* title, Storm* List[], int NStorms ) {
    // display NStorms storms
    // print some title and column headings; make a loop
    // and invoke function "PrintStorm" for each storm.

    cout << "Begin Date" << setw(10) << "Duration (hours)" << "Name" << setw(10)
    << "Category" << "Maximum Winds (mph)"
    << "Minimum Pressure (mb)" << endl;
    cout << "----------------------------------------------------------------" << endl;
    for(int i = 0; i < NStorms; i++)
    PrintStorm(*List);
    return;
    }

    int SaffirSimpson( int wind ) {
    // Compute storm category, using the Saffir-Simpson scale

    int category;

    if(wind > 134)
    category = 5;
    else if ((wind < 134) && (wind > 113))
    category = 4;
    else if ((wind < 113) && (wind > 96))
    category = 3;
    else if ((wind < 96) && (wind > 83))
    category = 2;
    else if ((wind < 83) && (wind > 64))
    category = 1;
    else if ((wind < 64) && (wind > 34))
    category = 'TS';
    else
    category = 'TD';

    return category;
    }

    void Sort( Storm* x[], int N ) {
    // bubble sort the list of Storm pointers
    int pass = 0, k, switches;
    Storm* temp;

    switches = 1;

    while( switches ) {
    switches = 0;
    pass++;
    for( k = 0; k < N - pass; k++ ) {
    if(x[k]->category < x[k + 1]->category) {
    temp = x[k];
    x[k] = x[k + 1];
    x[k + 1] = temp;
    switches = 1;
    }
    }
    }

    return;
    }

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    it compiled fine on my system but i dont have a data file to test it with

    if you have one post it here and i'll see what happens

Popular pages Recent additions subscribe to a feed