Thread: Compiler Crashing... WHY?

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    Compiler Crashing... WHY?

    Why would this be crashing?
    I am using this code:
    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <iomanip.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include <string.h>
    
    //Global Variables
    ifstream infile;
    ofstream outfile;
    
    typedef char string[30];
    
    //Prototypes
    void tocaps(string []);
    void bubblesort(string [],string [], string [], int);
    void cutoff(string []);
    void dashinsert(string []);
    int binarySearch(int list[],int size, int key);
    void report();
    
    int main()
    {
    string social[30],phone[30],name[30];
    int i;
    int numel=30;
    	infile.open("In599A.Dat");
    		while(!infile.eof())
    		{
    			for(i=0;i<23;i++)
    			{
    			infile>>social[i]>>phone[i];
    			infile.getline(name[i],30);
    			}
    		}
    //Function calls
    		bubblesort(name,social,phone,numel);
    return 0;
    }
    
    void bubblesort(string name[],string social[], string phone[], int numel)
    {
    	int i, j;
    	string temp;
    	for(i=0;i<numel-1;i++)
    		for(j=1;j<numel;j++)
    		{
    			if(strcmp(name[j],name[j-1])>0)
    			{
    			strcpy(temp,name[j]);
    			strcpy(name[j],name[j-1]);
    			strcpy(name[j-1],temp);
    
    			strcpy(temp,social[j]);
    			strcpy(social[j],social[j-1]);
    			strcpy(social[j-1],temp);
    
    			strcpy(temp,phone[j]);
    			strcpy(phone[j],phone[j-1]);
    			strcpy(phone[j-1],temp);			
    			}
    		}
    }

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Heh, your compiler is crashing, or your program is crashing? If it's really the compiler... i'd suggest getting a new one
    What compiler are you using, btw?

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    MS visual C++... its the program.. but when I run it, it doesn't even display

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    If it's crashing, and you're using arrays, that can only mean one thing...
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    which is....

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Your indexing into some array incorrectly.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    81
    actually, it works now, but I don't know how I fixed it... thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM