-4
此程序正在工作,但只能用數字。我需要它來處理字符串。我不知道如何做到這一點。沒有任何工作。我在尋求一些幫助。堆棧c中的字符串
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 20
struct stack
{
int stk[MAXSIZE];
int top;
};
typedef struct stack STACK;
STACK s;
void push (void);
void display (void);
void main()
{
int choice;
int option = 1;
s.top = -1;
while (option)
{
printf ("\nNacisnij 1 aby wprowadzic elemnt do stosu\n"); //press 1 to push on stack
printf ("Nacisnij 2 aby wyswietlic stan stosu\n"); //press 2 to display stack
printf ("Nacisnij 3 aby zakonczyc\n\n"); //press 3 to exit
scanf("%d", &choice);
switch (choice)
{
case 1:
push();
break;
case 2:
display();
break;
case 3:
return;
}
fflush (stdin);
}
}
void push()
{
int num;
if (s.top == (MAXSIZE - 1))
{
printf ("Stos jest pelen\n");// stack is full
return;
}
else
{
printf ("\nWprowadz element\n");// enter element
scanf("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
void display()
{
int i;
if (s.top == -1)
{
printf ("Stos jest pusty\n"); //stack is empty
return;
}
else
{
printf ("\nStan stosu\n"); //state of the stack
for (i = s.top; i >= 0; i--)
{
printf ("%d\n", s.stk[i]);
}
}
printf ("\n");
}
請打算您的代碼,並給我們一個實際的問題。 – deviantfan