פורסם 2007 בספטמבר 2318 שנים למה אני מקבל את השגיאה (הפרדוקסלית) הזאת ? 'MakeEmpty' : 'void (Stack)' differs in levels of indirection from 'void (Stack)'זה הפרוטוטייפ: void MakeEmpty(Stack S);זה הפונקציה:void MakeEmpty(Stack S) { if (S == NULL) { perror("must use CreateStack First"); exit(4); } else while (!IsEmpty(S)) Pop(S); }
פורסם 2007 בספטמבר 2318 שנים ראשית הרשה לי לברך אותך על השימוש ב-perror.שנית, כדאי שתסדר את ה-indentation כי כמו שהוא כתוב כרגע בפורום הוא די מטורף.הניחוש שלי זה שיש לך בעיה של מקרו.יתכן ש-Stack מוגדר איפהשהו (אפילו בלי ידיעתך) כמקרו. אולי MakeEmpty מוגדר כמקרו. אולי אפילו S.תזכור שזה יכול להיות אפילו בלי ידעתך (מאיזה קובץ של מישהו אחר) או בלי ששמת לב.בכל מקרה כדי לעזור לך הלאה נצטרך את ההגדרה של Stack.
פורסם 2007 בספטמבר 2318 שנים מחבר אין קריאה לפונקציה, זה קובץ h וקובץ מימוש שלו.stack הוא מצביע לסטראקט typedef struct Node *PtrToNode; typedef PtrToNode Stack;node הוא סטראקט.S לא מוגדר כמאקרו. (גם לא בלי ידיעתי)
פורסם 2007 בספטמבר 2318 שנים על איזו שורה בדיוק מצביעה השגיאה?מה ההגדרה של IsEmpty ן-Pop?(יעזור אם פשוט תעלה את כל הקוד...)
פורסם 2007 בספטמבר 2318 שנים מחבר השגיאה מצביעה על השורה שמסומנת בכוכביותstack.h #ifndef _Stack_h #define _Stack_h struct Node; typedef int ElementType ; typedef struct Node *PtrToNode; typedef PtrToNode Stack; int IsEmpty(Stack S); Stack CreateStack(void); void DisposeStack(Stack S); void MakeEmpty(Stack S); //********************* void Push(ElementType X, Stack S); ElementType Top(Stack S); void Pop(Stack S); #endif stack.c#include "STACK.h"#include <stdio.h>#include <stdlib.h>struct Node { ElementType Element; PtrToNode Next; };/* routine to test whether a stack is empty - linked list implementation */int IsEmpty(Stack S) { return S->Next == NULL; }/* routine to create an empty stack - linked list implementation */Stack CreateStack( void ) { Stack S; S = (Stack)malloc( sizeof( struct Node)); //casting if (S == NULL) { perror("Out of Space!"); exit(1); } S->Next = NULL; return S; }/* routine to empty an existing stack linked list implementation */void MakeEmpty(Stack S) { if (S == NULL) { perror("must use CreateStack First"); exit(4); } else while (!IsEmpty(S)) Pop(S); }/* routine to push onto a stack - linked list implementation */void Push(ElementType X, Stack S){ PtrToNode TmpCell; TmpCell = (Stack)malloc(sizeof( struct Node)); //casting if (TmpCell == NULL) { perror("Out of Space!"); exit(2); } else { TmpCell->Element=X; TmpCell->Next = S->Next; S->Next = TmpCell; } }/* routine to return top element in a stack - linked list implementation */ElementType Top(Stack S) { if (!IsEmpty( S )) return S->Next->Element; { perror("Empty stack"); exit(2); } return 0; /* return value used to avoid warning */ }/* routine to pop from a stack - linked list implementation */void Pop (Stack S){ PtrToNode FirstCell; if (IsEmpty( S )) { perror("Empty stack"); exit(3); } else { FirstCell = S->Next; S->Next = S->Next->Next; free (FirstCell); } }
פורסם 2007 בספטמבר 2318 שנים ואללה, אין לי מושג.תגיד, למה הגדרת את Node בתוך הקובץ c ולא הקובץ h? (אני בספק אם זו הבעיה, אבל זה סתם מתמיה)
פורסם 2007 בספטמבר 2318 שנים באיזה קומפיילר אתה משתמש?ניסיתי לקמפל אצלי (VS2005) וזה התקמפל (לא התלנקג' כי אין main, אבל זה לא רלוונטי).
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.