Re: why does it crash?

From: Moonlit (alt.spam_at_jupiter.universe)
Date: 10/10/03


Date: Fri, 10 Oct 2003 21:28:17 +0200

Hi,

Could you be more specific at which line it crashes, I compiled it and it
runs for me (that doesn't say it is correct though).

BTW Using vectors and STL stuff would have reduced your code to a few lines.
To get some ideas:

#include <algorithm>
#include <string>

using namespace std;

class CCityInfo
{
  string CityName;
  int Temp;
// Constructor stuff and init etc public keywords Get and Put functions
etc..
  bool operator <( const CCityInfo& City1 ) const
  {
    return Temp < City1.Temp;
  }
};
vector<CCityInfo> Cities;

sort( Cities.begin(), Cities.end() );

-------------------------------------------------------
[root@moonlit root]# ./r

Please enter name of city#1: 1

Please enter 1's temp: 2

Another city?(Y/N)y

Please enter name of city#2: 3

Please enter 3's temp: 2

Another city?(Y/N)n

name of city temperature
    1 2
    3 2

name of city temperature
    1 2
    3 2
------------------------------------------------------------

"Developwebsites" <developwebsites@aol.combatSPAM> wrote in message
news:20031010150519.17356.00000063@mb-m03.aol.com...
> this program compiles, but crashes when run.
> whats wrong with it?
>
> #include<iostream.h>
> #include<iomanip.h>
>
> int numb_cities=0;
> const int MAX = 120;
>
> class Cities {
> private:
> char cityname[MAX][MAX];//an array of 120 cities.
> int temp[MAX];
>
> public:
> void input();
> void output();
> void sort();
> };
>
>
> void Cities::input()
> {
> char y_n;
> do{
> cout<<"\n\n";
> cout<<"Please enter name of city#"<<numb_cities+1<<": ";
> cin>>cityname[numb_cities];
> cout<<"\nPlease enter "<<cityname[numb_cities]<<"'s temp: ";
> cin>>temp[numb_cities];
> numb_cities++;
> cout<<"\nAnother city?(Y/N)";
> cin>>y_n;
> }while(y_n =='y' || y_n =='Y');
> cout<<"\n\n";
> }
>
> void Cities::output()
> {
> cout<<"\n"<<"name of city"
> <<" temperature"
> <<"\n";
> for(int t=0;t<numb_cities;t++)
> {
> cout<<setw(5)<<cityname[t]<<setw(15)<<temp[t]<<"\n";
> }
> }//close output
>
> void Cities::sort()
> {
> char citynametemp[MAX][MAX];
> int tempt;
> for(int a=0;a<numb_cities;a++) {
> for(int b=a+1; b<numb_cities;b++) {
> if (temp[a]<temp[b]) {
> tempt = temp[a];
> temp[a] = temp[b];
> temp[b] = tempt;
> citynametemp[MAX][MAX] = cityname[a][MAX];
> cityname[a][MAX] = cityname[b][MAX];
> cityname[b][MAX] = citynametemp[MAX][MAX];
> }//close if
> }//close b loop
> }//close a loop
> }//close sort
>
>
> int main()
> {
> Cities info;
>
> info.input();
> info.output();
> info.sort();
> info.output();
> return 0;
> }
> --------------------------------------------------
> remove *batSPAM* to e-mail me
> --------------------------------------------------



Relevant Pages

  • Re: Calling a managed function from native code
    ... running on top of the CLR but which is isn't garbage collected. ... compiles to IL which is JIT compiled and runs on top of the CLR. ... void test() { ... You can't do that, String is not disposable, it doesn't have a destructor, it doesn't have a Dispose method. ...
    (microsoft.public.dotnet.languages.vc)
  • (no subject)
    ... your module compiles fine on my box using this method ... > I have tried to compile the hello.c module under kernel 2.6.3. ... > int initial_module (void) ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Linux compiling
    ... For a start, void main has *never* been correct and as Jack has said, it ... but what they hey, it compiles doens't it!" ... a warning - so from slightly broken to completely broken happened. ... It is a biggy and to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: CW10 assignment, void*, func ptr warnings...
    ... In any case, your code compiles just fine in my application, so I don't ... know why you're getting a warning. ... > when going from the void* back to a func ptr cast. ...
    (comp.sys.mac.programmer.codewarrior)
  • Re: vulnerabilities
    ... Even if it compiles, ... >void memset ... I guess C++ allows using the memset ... Dan Pop ...
    (comp.lang.c)