c - Confused about this while statement -


i wrote program class , can't seem while loop work.. don't know wrong, it's small error know make tons of... thanks! ps i'm new stuff easy on me if small :p

#include <stdio.h>  #define stack_size 10 #define true 1 #define false 0 #define maxnum 5  /*************** prototypes ***************/ void make_empty(int *top); int is_full(int *top); int push(int content[], int maxnum, int newnum, int *top); int pop(int contents[], int maxmun, int *top); void printstack(int contents[], int maxnum, int *top); int is_empty(int *top); int search(const int content[], int maxnum, int num);  // main function int main(void) {     int popnum = 0;     int foundindex = -1;     int i;     int contents[stack_size] = { 0 };     int top = 0;     int input = 0;       while (! == 0)     {         printf("/n/npick number 1 5, type number press enter: ");         switch (input)         {         case 1:             push(contents, maxnum, popnum, &top);             break;         case 2:             if (pop(contents, maxnum, &top) <= 0)                 printf("error popping stack \n");             break;         case 3:             make_empty(&top);             break;         case 4:             printstack(contents, maxnum, &top);         }//end loop switch      }  } // end main()  /****************************************** ** ** make_empty function ** ** ******************************************/  void make_empty(int *top) {     *top = 0; }  /****************************************** ** ** is_empty function ** ** ******************************************/  int is_empty(int *top) {     if (*top == 0)         return true;     else         return false; }  /****************************************** ** ** is_full function ** ** ******************************************/  int is_full(int *top) {     static int ncalls = 0; // static variable      ncalls++;     if (*top == stack_size)         return true;     else         return false; }  /****************************************** ** ** push function ** ** ******************************************/  int push(int content[], int maxnum, int newnum, int *top) {     int ncalls = 0;     ncalls++;     if (is_full(top))         return false;     else         content[(*top)++] = newnum; }  /****************************************** ** ** pop function ** ** ******************************************/  int pop(int contents[], int maxmun, int *top) {     if (is_empty(top))         return false;     else         return contents[--(*top)]; }  /******************************* ** ** printstack fuction ** ** ******************************/ void printstack(int contents[], int maxnum, int *top) {     int i;     if (!is_empty(top))     {         (i = 0; < *top; i++)             printf("number %d = %d\n", i, contents[i]);     }     else         printf("stack empty"); }  /******************************* ** ** search function ** ** ******************************/ int search(const int content[], int maxnum, int num) {      int findex = -1;      (int = 0; < maxnum; i++)     {         if (content[i] == num)         {             findex = i;             break;         }     }      return (findex);  }  /*     */ 

issue 1 >> while (! == 0)

if want loop unconditionally, use while (1), , inside switch case, add default (or numbered) case hold break statement come of loop.

issue 2 >> switch (input)

you seem to plan asking user input, did not code that. before switching based on input value, need value user , store input variable. make use of scanf() function. read man page details.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -