أرجوكم يا جماعة ماهي المشكلة في هذا البرنامج ..ال(compiler) لم لم يعطيني خطأ ولكن إذا نفذته وأدخلت الdataالأولى يقولى:تسبب البرنامج...في حدوث خطأ وسوف يتم إغلاقه.....إلى آخر السمفونية المقيتة :wacko: ,هل المشكلة في الفيجوال أم بخطأ لم يكتشفه ال(compiler)
#include<stdio.h>
#include<stdlib.h>
struct intstack
{
int *AryStack;
int count;
int maxary;
int top;
};
struct intstack* createstack(int maxelements)
{
struct intstack *stack;
stack=(struct intstack*)malloc(sizeof(struct intstack));
if(stack==NULL)
return NULL;
stack->count=0;
stack->top=-1;
stack->maxary=maxelements;
stack->AryStack=(int*)malloc(sizeof(int)*maxelements);
if(stack->AryStack==NULL)
free(stack);
return NULL;
return stack;
}
int pushstack(struct intstack *stack,int datain)
{
if(stack->count==stack->maxary)
return 0;
(stack->count)++;
(stack->top)++;
stack->AryStack[stack->top]=datain;
return 1;
}
int popstack(struct intstack *stack,int *dataout)
{
if(stack->count==0)
return 0;
*dataout=stack->AryStack[stack->top];
(stack->count)--;
(stack->top)--;
return 1;
}
int topstack(struct intstack *stack,int *dataout)
{
if(stack->count==0)
return 0;
*dataout=stack->AryStack[stack->top];
return 1;
}
int emptystack(struct intstack *stack)
{
return (stack->count==0);
}
int fullstack(struct intstack *stack)
{
return (stack->count==stack->maxary);
}
void main()
{
struct intstack *mystack;
int i;
int value;
mystack=createstack(10);
while(1)
{
printf("stack manipulation:\n\n");
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Pop\n");
printf("4.End\n\n");
scanf("%d",&i);
if(i==1)
{
printf("Value?");
scanf("%d",&value);
if(pushstack(mystack,value))
printf("value%dpushed in\n",value);
else
printf("stack is full");
}
else if(i==2)
{
if(popstack(mystack,&value))
printf("value %d poped\n",value);
else
printf("stack is Empty\n");
}
else if (i==3)
{
if(topstack(mystack,&value))
printf("value on the top is %d\n",value);
else
printf("stack is Empty \n");
}
else
return;
}
}
