assignment 5 - return (0); } void readPush() { int i=1;...

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

View Full Document Right Arrow Icon
/* Assignment 5, Part A, Question 1 */ #include <stdio.h> #include <ctype.h> #include <stdlib.h> #define STRLMT 12 void separate(char[]); char tempmonth[STRLMT]; char tempdate [STRLMT]; char date[STRLMT]; int main() { printf("Enter a month and date(e.g. June 14):\n"); gets(date); separate(date); printf("The month entered is \n\n"); puts(tempmonth); printf("\nThe date entered is \n \n"); puts(tempdate); return(0); } void separate(char date[])
Background image of page 1

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

View Full DocumentRight Arrow Icon
{ int i= 0 , a = 0; for(i = 0; date[i] != '\0'; i++) { if (isalpha(date[i])) tempmonth[i] = date[i]; if (isdigit(date[i])) { tempdate[a] = date[i]; a++; } } } /* Assignment 5, Part B, Question 1 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXCHAR 30 #define DEBUG 0 struct ValLog { char value[MAXCHAR]; struct ValLog *priorAddr; }; struct ValLog *tosp;
Background image of page 2
int main() { void readPush(); void popShow(); tosp = NULL; readPush(); popShow(); readPush(); popShow();
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return (0); } void readPush() { int i=1; char value[MAXCHAR]; void push(char *); printf(&quot;Enter 5 values, one per line.\n \n&quot;); for(i=1; i &lt;= 5; i++) { printf(&quot;Enter a value: &quot;); gets(value); push(value); } } void popShow() { char value[MAXCHAR]; void pop(char *); printf(&quot;\n The values popped from the stack are:\n&quot;); while (tosp != NULL) { pop(value); printf(&quot;%s%\n&quot;, value); } } void push(char *value) { struct ValLog *newaddr; newaddr = (struct ValLog *) malloc(sizeof(struct ValLog)); if(newaddr == (struct ValLog *) NULL) { printf(&quot;\nFailed to allocate memory for this structure\n&quot;); exit(1); } strcpy(newaddr-&gt;value, value); newaddr-&gt;priorAddr = tosp; tosp = newaddr; } void pop(char *value) { struct ValLog *tempAddr; strcpy(value, tosp-&gt;value); tempAddr = tosp-&gt;priorAddr; free(tosp); tosp = tempAddr; }...
View Full Document

Page1 / 5

assignment 5 - return (0); } void readPush() { int i=1;...

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

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