| | |
Troubleshooting Segmentation Fault Involving Pointer
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
0
#11 Nov 4th, 2009
To avoid buffer overflow, prefer using
>> With that code, calling the >> operator will always store it into appt.subject, but what about storing information to appt.location? Any suggestions on an approach?
Actually there are more than one ways to do that. Simplest being :
However you get few problems:
1. Cant use space, in strings
2. Buffer overflow
3. Will surely confuse the user
So you print message before every input like you do in normal program:
cin.getline(char_ptr, size);>> With that code, calling the >> operator will always store it into appt.subject, but what about storing information to appt.location? Any suggestions on an approach?
Actually there are more than one ways to do that. Simplest being :
C++ Syntax (Toggle Plain Text)
in >> subject >> location
However you get few problems:
1. Cant use space, in strings
2. Buffer overflow
3. Will surely confuse the user
So you print message before every input like you do in normal program:
C++ Syntax (Toggle Plain Text)
cout << "\nEnter Location: "; in.getline(location, 60); cout << "\nEnter Subject: " in.getline(subject, 60);
Last edited by vishesh; Nov 4th, 2009 at 6:17 pm.
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#12 Nov 4th, 2009
The second one is exactly what I'm looking for. I don't know how I forgot about using getline. My problem is, how would I call that operator in the first place? I feel like the order would be off.
I very specifically have to have my Day class call this Appointment class, which is how it is now, but then wouldn't I need some sort of cout statement before I call the >> operator? In which case, wouldn't I then have cout statements in both my makeAppt() function and also in my overloaded operator? It seems messy to me. Or I'm missing something.
I very specifically have to have my Day class call this Appointment class, which is how it is now, but then wouldn't I need some sort of cout statement before I call the >> operator? In which case, wouldn't I then have cout statements in both my makeAppt() function and also in my overloaded operator? It seems messy to me. Or I'm missing something.
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#13 Nov 4th, 2009
So I think part of my problem is that I haven't fully explained exactly what I am looking for. Both of your responses are spot on, I understand them, but they don't quite fit my need here and I'm not sure how to adapt them. Let me try to clarify.
The exact console should look like this:
Calendar Menu
0. Done.
1. Search for date.
2. Search for subject.
3. Add an appointment.
Your choice >> 3
Please enter the month and day (mm/dd) >> 10/29
Subject >> Appointment
Location >> 3052 Kemper
Start time >> 6:15 PM
End time >> 7:37 PM
The overloaded >> operator in the Day class will then call the overloaded >> operator or the Appointment class (what we've been talking about this whole time), which will finally call the overloaded >> operator in the Time class.
Therefore, I need to use the overloaded operator in my Appointment class to read in an Appointment and store the user input to *location and *subject, but they must be on separate lines, as shown above.
And thank you two for all your help. I'm writing down all of what you've told me as it's invaluable, even beyond thescope of my current assignment.
The exact console should look like this:
Calendar Menu
0. Done.
1. Search for date.
2. Search for subject.
3. Add an appointment.
Your choice >> 3
Please enter the month and day (mm/dd) >> 10/29
Subject >> Appointment
Location >> 3052 Kemper
Start time >> 6:15 PM
End time >> 7:37 PM
The overloaded >> operator in the Day class will then call the overloaded >> operator or the Appointment class (what we've been talking about this whole time), which will finally call the overloaded >> operator in the Time class.
Therefore, I need to use the overloaded operator in my Appointment class to read in an Appointment and store the user input to *location and *subject, but they must be on separate lines, as shown above.
And thank you two for all your help. I'm writing down all of what you've told me as it's invaluable, even beyond thescope of my current assignment.
•
•
Join Date: Mar 2009
Posts: 24
Reputation:
Solved Threads: 9
0
#14 Nov 4th, 2009
•
•
•
•
I very specifically have to have my Day class call this Appointment class, which is how it is now, but then wouldn't I need some sort of cout statement before I call the >> operator? In which case, wouldn't I then have cout statements in both my makeAppt() function and also in my overloaded operator? It seems messy to me. Or I'm missing something.
makeAppt to operator>> and leave the appointment prompting in operator>> . C++ Syntax (Toggle Plain Text)
void Appointment::makeAppt() { cin >> *this; }
![]() |
Similar Threads
- mysterious segmentation fault (C)
- segmentation fault: causes. (C++)
- Segmentation fault in quick and merge sorts (C)
- Segmentation Fault (C++)
- help on 'Segmentation Fault' (C)
- segmentation fault (C)
- what is the best way to track segmentation fault errors (C++)
Other Threads in the C++ Forum
- Previous Thread: Some thoughts
- Next Thread: How to insert data in CLOB column
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






