C++ techs help me!, C++ abrupt termination.. |
![]() ![]() |
C++ techs help me!, C++ abrupt termination.. |
Mar 8 2008, 05:50 AM
Post
#1
|
|
|
New Member ![]() Posts: 4 OS: windows XP |
i m a learner in OOP C++ programming... d problem dat i m facing is the abrupt termination of C++ when i execute a program...let me explain in detail.. wen i run a program..smtimes it runs well and fine widout any problem...but wen i exit the program the TC.exe terminates abruptly i thnk d reason behind mite be like dis : during d program execution...somehow d memory location of TC.exe mite be gettin overwritten by some or d other component of d program...however dis is my guess... sooo...is dere neone who can help me out here ??? i want a perfect reason and a solution to that.... |
|
|
Mar 20 2008, 02:20 AM
Post
#2
|
|
|
Member ![]() ![]() ![]() Posts: 110 From: South Carolina OS: Windows XP Media Center Edition |
Got any code for us to look at? Got anything else than what you provided? It doesn't seem like you provided anything at all except the knowledge that you have a problem...
|
|
|
Mar 20 2008, 02:28 AM
Post
#3
|
|
|
New Member ![]() Posts: 4 OS: windows XP |
okkk...
here is my code.. look at the code with ease... //Program implementing a string class and all the related //operations... #include "iostream.h" #include "conio.h" #include "stdlib.h" class strings //Class definition { char *string; //for the string data public: int len; //for lenght of string strings() //Default constructor {*string = NULL;len = 0;} strings(char *a) //Parameterized constructor { len = str_len(a); /*while (*a) len++;*/ //*a -= len; string = new char[len+1]; while (*a) { *string = *a; string++; a++; } *string = '\0'; string -= len; } // ~strings() //Destructor freeing memory // {delete []string;} void getdata() //When the entry is going to be taken from user { delete [] string; char *a; cout << endl << endl <<"Enter the string to be operated upon (Maxlength = 100): "; cin.getline (a,100); len = str_len(a); //while (*a) // len++; //a -= len; string = new char[len+1]; while (*a) { *string = *a; string ++; a++; } *string = '\0'; string -= len; } void displaydata() //Displaying data to the user { cout << endl << endl << "Your string is : " << string; } //Function Declarations which will operate on the string void strcpy(strings &); }; void strings::strcpy (strings &source) { delete []string; string = new char[source.len+1]; while (*source.string) { *string = *source.string; string ++; source.string++; } *string = '\0'; string -= len; } int str_len (const char *a) { int len = 0; while (*a) { len++; a++; } return len; } void main() { clrscr(); char *str; int choice; strings main_string; //Taking entry for the main string main_string.getdata(); clrscr(); do { clrscr(); //Providing menu cout << "\t\tMenu for the operations on the given string" << endl << "1. Change the Main String." << endl << "2. Display the string." << endl << "3. Count the length of the string." << endl << "4. Copy a string into the main string." << endl << "0. Exit" << endl; //Taking choice cout << endl << "Enter the no. of your choice here : "; cin >> choice; cin.ignore(); //Taking actions switch (choice) { case 1: main_string.getdata(); break; case 2: main_string.displaydata(); cin.get(); break; case 3: cout << endl << "Length of the string = " << main_string.len; cin.get(); break; case 4: cout << endl <<"Enter a string to be copied (Maxlength = 100) : "; cin.getline(str,100); strings temp_string (str); temp_string.displaydata(); cin.get(); main_string.strcpy(temp_string); break; case 0: cout << endl << "\t\t\t\tThank You"; cin.get(); exit(0); break; default : cout << endl << "\t\t\t\tWrong Entry"; cin.get(); break; } getch(); } while (choice != 0); } i am also attaching the .cpp file... |
|
|
Mar 20 2008, 02:28 AM
Post
#4
|
|
|
New Member ![]() Posts: 4 OS: windows XP |
okkk...
here is my code.. look at the code with ease... CODE //Program implementing a string class and all the related //operations... #include "iostream.h" #include "conio.h" #include "stdlib.h" class strings //Class definition { char *string; //for the string data public: int len; //for lenght of string strings() //Default constructor {*string = NULL;len = 0;} strings(char *a) //Parameterized constructor { len = str_len(a); /*while (*a) len++;*/ //*a -= len; string = new char[len+1]; while (*a) { *string = *a; string++; a++; } *string = '\0'; string -= len; } // ~strings() //Destructor freeing memory // {delete []string;} void getdata() //When the entry is going to be taken from user { delete [] string; char *a; cout << endl << endl <<"Enter the string to be operated upon (Maxlength = 100): "; cin.getline (a,100); len = str_len(a); //while (*a) // len++; //a -= len; string = new char[len+1]; while (*a) { *string = *a; string ++; a++; } *string = '\0'; string -= len; } void displaydata() //Displaying data to the user { cout << endl << endl << "Your string is : " << string; } //Function Declarations which will operate on the string void strcpy(strings &); }; void strings::strcpy (strings &source) { delete []string; string = new char[source.len+1]; while (*source.string) { *string = *source.string; string ++; source.string++; } *string = '\0'; string -= len; } int str_len (const char *a) { int len = 0; while (*a) { len++; a++; } return len; } void main() { clrscr(); char *str; int choice; strings main_string; //Taking entry for the main string main_string.getdata(); clrscr(); do { clrscr(); //Providing menu cout << "\t\tMenu for the operations on the given string" << endl << "1. Change the Main String." << endl << "2. Display the string." << endl << "3. Count the length of the string." << endl << "4. Copy a string into the main string." << endl << "0. Exit" << endl; //Taking choice cout << endl << "Enter the no. of your choice here : "; cin >> choice; cin.ignore(); //Taking actions switch (choice) { case 1: main_string.getdata(); break; case 2: main_string.displaydata(); cin.get(); break; case 3: cout << endl << "Length of the string = " << main_string.len; cin.get(); break; case 4: cout << endl <<"Enter a string to be copied (Maxlength = 100) : "; cin.getline(str,100); strings temp_string (str); temp_string.displaydata(); cin.get(); main_string.strcpy(temp_string); break; case 0: cout << endl << "\t\t\t\tThank You"; cin.get(); exit(0); break; default : cout << endl << "\t\t\t\tWrong Entry"; cin.get(); break; } getch(); } while (choice != 0); } now check out the code... |
|
|
![]() ![]() |
Similar Topics
| Topic Title | Replies / Views | Topic Information | |||||
|---|---|---|---|---|---|---|---|
![]() |
0 / 72 | 8th March 2008 - 11:29 PM Encrypted Devil started - last by Encrypted Devil |
|||||
![]() |
0 / 66 | 28th June 2008 - 12:45 PM wazz started - last by wazz |
|||||
![]() |
1 / 94 | 1st July 2008 - 01:22 AM virusabhi started - last by Mike |
|||||
![]() |
4 / 161 | 3rd July 2008 - 12:54 PM Znake started - last by Rorschach112 |
|||||
![]() |
1 / 76 | 22nd July 2008 - 01:55 PM staceluvzdorks started - last by Neil Jones |
|||||
|
Time is now: 20th August 2008 - 12:11 PM |
| Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm to your computer. However, we do not guarantee that they are accurate and they are to be used at your own risk. |