Click here to Skip to main content
15,914,225 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Memory Limits Pin
Obi Wan 225-Mar-05 17:21
Obi Wan 225-Mar-05 17:21 
GeneralRestart the process Pin
mpapeo25-Mar-05 13:38
mpapeo25-Mar-05 13:38 
GeneralRe: Restart the process Pin
Anand for every one25-Mar-05 21:41
Anand for every one25-Mar-05 21:41 
GeneralRe: Restart the process Pin
mpapeo26-Mar-05 9:00
mpapeo26-Mar-05 9:00 
GeneralActiveX in C++ Pin
j1webb25-Mar-05 12:36
j1webb25-Mar-05 12:36 
General<<NEWB-Troubles with stacks Pin
rdt25325-Mar-05 11:48
rdt25325-Mar-05 11:48 
GeneralRe: <<NEWB-Troubles with stacks Pin
Paul M Watt25-Mar-05 12:56
mentorPaul M Watt25-Mar-05 12:56 
GeneralRe: <<NEWB-Troubles with stacks Pin
FlyingTinman25-Mar-05 13:05
FlyingTinman25-Mar-05 13:05 
Decare a CString variable to be your "stack" (or a CArray of type char )

Initialize it to be empty.

Write a function : void Push(char) which adds one character to the end of the CString.
Write a function : char Pop() which returns the character at the end of the CString then removes it (or returns an error value if the string is empty)

Now write a main loop that read in chars from your file one at a time.
1) If it finds a left brace, paren or bracket it must call Push(char) and add it to the string
2) If it finds a right brace, paren or bracket it must call Pop() and compare the result to the char just read in.
3) If it finds any other character ignore it keep looping :

In case 2) (right symbol read in from file)
If Pop() returns a matching left symbol it can carry on looping.
If Pop() returns a non-matching left symbol then the input was invalid.
If Pop() returns the error value because the CString is empty then the input was invalid.

If your reach the end of file with no previos fail:
Call Pop() and check for the error value (CString empty)
If the CString (your stack) is empty (Pop() returns error value) the input was valid.
If the CString (your stack) is not empty the input was invalid.

[edit]
I suggested the CString or CArray so you don't have to worry about memory management as the stack (whose max required size will be unknown) grows: If the exercise is intended to demonstrate your ability to allocate and free memory dynamically then you will need to use char* instead of CString/CArray and allocate an initial amount of memory for the stack and each time you add a char check to see if it needs more allocated.
[/edit]

Steve T
GeneralRe: &lt;&lt;NEWB-Troubles with stacks Pin
rdt25325-Mar-05 15:42
rdt25325-Mar-05 15:42 
GeneralRe: &lt;&lt;NEWB-Troubles with stacks Pin
David Crow25-Mar-05 16:03
David Crow25-Mar-05 16:03 
GeneralRe: &lt;&lt;NEWB-Troubles with stacks Pin
rdt25325-Mar-05 16:11
rdt25325-Mar-05 16:11 
GeneralRe: &lt;&lt;NEWB-Troubles with stacks Pin
David Crow26-Mar-05 7:07
David Crow26-Mar-05 7:07 
GeneralAccessing and displaying data of worker thread function Pin
Member 153706925-Mar-05 11:11
Member 153706925-Mar-05 11:11 
GeneralRe: Accessing and displaying data of worker thread function Pin
Paul M Watt25-Mar-05 12:59
mentorPaul M Watt25-Mar-05 12:59 
GeneralRe: Accessing and displaying data of worker thread function Pin
PJ Arends25-Mar-05 13:04
professionalPJ Arends25-Mar-05 13:04 
GeneralSaving Bitmap From Clipboard to file Pin
ww303125-Mar-05 8:18
ww303125-Mar-05 8:18 
GeneralRe: Saving Bitmap From Clipboard to file Pin
David Crow25-Mar-05 9:21
David Crow25-Mar-05 9:21 
GeneralRe: Saving Bitmap From Clipboard to file Pin
ww303125-Mar-05 11:01
ww303125-Mar-05 11:01 
GeneralVC++ 2003 .NET Pin
victorsk25-Mar-05 7:27
victorsk25-Mar-05 7:27 
GeneralRe: VC++ 2003 .NET Pin
Kevin McFarlane25-Mar-05 10:16
Kevin McFarlane25-Mar-05 10:16 
GeneralRe: VC++ 2003 .NET Pin
victorsk25-Mar-05 11:00
victorsk25-Mar-05 11:00 
GeneralRe: VC++ 2003 .NET Pin
Kevin McFarlane25-Mar-05 11:08
Kevin McFarlane25-Mar-05 11:08 
GeneralRe: VC++ 2003 .NET Pin
MMansonFan2529-Mar-05 23:19
MMansonFan2529-Mar-05 23:19 
GeneralUDP datagram, Pls help Pin
Kimdave25-Mar-05 6:46
Kimdave25-Mar-05 6:46 
QuestionAfxBeginThread() ??? Pin
Static(x)25-Mar-05 6:25
Static(x)25-Mar-05 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.