hmwk1_probSet_ch

hmwk1_probSet_ch - COMPE 271 FALL 2010 Semester HOMEWORK 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COMPE 271 FALL 2010 Semester HOMEWORK 1 Due 9/22/2010 Homework Part 1 #include <stdio.h> #include <stdlib.h> int stackPointer; char push ( char *stackArray, char value) { // Todo :Please note that the stack pointer's value must be within 0 and 99. // Todo :Modify the function to return -1 if the value of stackPointer is not within limits // Todo :Avoid writing to the stack area of the value of stack pointer is not within limits stackPointer = stackPointer - 1; stackArray[stackPointer] = value; return (value); } char pop ( char *stackArray) { // Todo :Please note that the stack pointer's value must be within 0 and 99. // Todo :Modify the function to return -1 if the value of stackPointer is not within limits // Todo :Avoid writing to the stack area of the value of stack pointer is not within limits char value; value = stackArray[stackPointer]; stackPointer = stackPointer + 1; return (value); } int main ( void ) { char *stackArray; char value; // Todo : The following line of code allocates 100 bytes dynamically and assigns the memory allocated to pointer stackArray. // Todo : There is however no control for the memory allocation. If the memory allocation fails we will have a null pointer // Todo : Add appropriate code to make sure the memory allocation is successfull before continuing with the rest of the code // Todo : if memory allocation is not successfull , print a message of your choise to inform the user and exit the program. stackArray = (
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/07/2011 for the course COMPE 271 taught by Professor Staff during the Fall '08 term at San Diego State.

Page1 / 3

hmwk1_probSet_ch - COMPE 271 FALL 2010 Semester HOMEWORK 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online