עבור לתוכן

שגיאה בC שאלה נוספת

Featured Replies

פורסם

איזה סיבות יכולות להיות להופעת השגיאה הזאת?:

error C2061: syntax error : identifier 'List'

השגיאה מופיעה בקובץ LIST.c

List מוגדר (typedef) בקובץ LIST.h אשר יש בו אינקלוד לLIST.c

ובלי קשר:

יש איזה אתר שמרוכזים בו הסברים לשגיאות של קומפיילרים?

פורסם

list.h עושה אינקלוד ל-list.c? למה?

זה אמור להיות להיפך.

חוץ מזה, הוא אומר לך שהוא לא מכיר משהו בשם List.

אני לא מכיר אתר כזה, אבל חיפוש בגוגל של מספר השגיאה (2061) כמעט תמיד ימצא לך פירוט.

פורסם
  • מחבר

תודה.

פורסם

ב MSDN (גם במה שמצורף ל VS ) יש הסברים קצרים על קודי שגיאות ובדר"כ דוגמה. ב VS 2005 (אני חושב שגם בגירסאות קודמות פשוט אני עובד עם ה 2005) אתה יכול פשוט לבחור את השגיאה (בחלונית Error List ) וה Dynamic Help יציג לך קישור לערך בעזרה.

פורסם
  • מחבר

נכון (גם לגבי 2003)

תודה.

פורסם
  • מחבר

למה בשורה הזאת:

S->Array = malloc(sizeof(ElementType) * MaxElements);

בפונקציה CreateStack

בתכנית הזאת:

http://info.ee.surrey.ac.uk/Teaching/Courses/DSCA/stack_adt.html

אני מקבל את השגיאה הזאת:

c:\users\יעקובי אורן\documents\visual studio projects\44444\stack.c(18): error C2065: 'Array' : undeclared identifier

?

פורסם

יש שם שני מימושים למחסנית, אחד בעזרת רשימה מקושרת ואחד בעזרת מערך. תראה שאתה לא מערבב בטעות בין השניים (ה Array מוגדר רק במימוש בעזרת מערך).

פורסם
  • מחבר

שמתי לב לזה ולא ערבבתי.

אני לא מוצא מה הבעיה, אני משער שזה בגלל שבסטראקט הARRAY הוא מצביע

ואולי ההצבעה אליו בפונקציה לא נכונה

פורסם

קודם כל, שים לב שבקוד הזה יש שגיאה:

typedef sruct StackRecord *Stack;

זה אמור להיות struct, לא sruct.

חוץ מזה, הגדרת את ElementType?

פורסם
  • מחבר

כן , הגדרתי את elementtype

וגם שמתי לב לטעות הזאת

ועדיין השגיאה מופיעה

פורסם
  • מחבר

stack.h

 #ifndef _Stack_h
#define _Stack_h
struct StackRecord;
typedef struct StackRecord *Stack;
typedef int ElementType;
int IsEmpty(Stack S);
int IsFull(Stack S);
Stack CreateStack(int MaxElements);
void DisposeStack(Stack S);
void MakeEmpty(Stack S);
void Push(ElementType X, Stack S);
ElementType Top(Stack S);
void Pop(Stack S);
ElementType TopAndPop(Stack S);
#endif

stack.c:

#include "Stack.h"
#include <stdlib.h>
#define EmptyTos (-1) // symbol of an empty stack
#define MinStackSize (5) //minimum size of stack
struct StackRecord
{
int Capacity; //maximum size of stack
int TopOfStack; //head of stack index to array element
ElementType *Array; //pointer to array to the bottom of the stack
};
/* stack creation array implementation */
Stack CreateStack(int MaxElements)
{
Stack S;
if (MaxElements < MinStackSize) { perror("Stack size is too small"); exit(1); }
S = (Stack)malloc(sizeof( struct StackRecord ));
if (S == NULL) { perror("out of space!"); exit(2); }
S->Array = (Array)malloc(sizeof(ElementType) * MaxElements);
if (S -> Array == NULL) { perror("out of space!"); exit(4); }
S->Capacity = MaxElements;
MakeEmpty(S); //S->TopofStack=EmptyTos
return S;
}


/* routine for freeing stack array implementation */
void DisposeStack(Stack S)
{
if (S != NULL)
{
free(S->Array); //free the ElementType array
free(S); //free the StackRecord
}
}



/* routine to test whether a stack is empty array implementation */
int IsEmpty(Stack S)
{
return S->TopOfStack == EmptyTos;
}


/* routine to create an empty stack array implementation */
void MakeEmpty(Stack S)
{
S->TopOfStack = EmptyTos;
}


/* routine to push onto a stack array implementation */
void Push(ElementType X, Stack S)
{
if (IsFull( S )) { perror("Full stack"); exit(6); }
else S->Array[++(S->TopOfStack)] = X; // 1 is added to TopOfStack
// if the stack is empty then ++(S->TopOfStack) = ++(-1) = 0
}




/* routine to return top of stack array implementation */
ElementType Top(Stack S)
{
if (!IsEmpty(S)) return S->Array[S->TopOfStack];
{ perror("Empty stack"); exit(3); }
return 0; /* return value used to avoid warning */
}




/* routine to pop from a stack array implementation */
void Pop(Stack S)
{
if (IsEmpty( S)) { perror("Empty stack"); exit(5); }
else S->TopOfStack--;
}




/* routine to give top element and pop a stack array implementation */
ElementType TopAndPop(Stack S)
{
if (!IsEmpty( S )) return S->Array[S->TopOfStack--];
{ perror("Empty stack"); exit(3); }
return 0; /* return value used to avoid warning */
}


ElementType TopAndPop( Stack S )
{ if ( !IsEmpty( S ) ) return S->Array[S->TopOfStack--];
{ perror("Empty stack"); exit(3); }
return 0 ; /* Return value used to avoid warning */
}


void DisposeStack( Stack S )
{ if (S != NULL ) { free(S->Array);
free( S ); }
}

פורסם

בשורה:

S->Array = (Array)malloc(sizeof(ElementType) * MaxElements);

ה (Array) לא נמצא בקוד שבאתר (זה בעצם cast ולא קיים טיפוס שנקרא Array). אם כבר אז תעשה cast ל ElementType* .הקוד באתר הוא:

 S->Array = malloc(sizeof(ElementType) * MaxElements);

בנוסף חסר המימוש ל IsFull.

פורסם
  • מחבר

נכון

תודה.

פורסם
  • מחבר

האם הפונקציות האלה שקולות?

        Position Find( ElementType X, List L)
{
Position P;
P = CursorSpace[L].Next;
if(P && CursorSpace[P].Element !=X )
Find(X,P);
return P;
}

        Position Find( ElementType X, List L)
{
Position P;
P = CursorSpace[L].Next;
while (P && CursorSpace[P].Element !=X )
P = CursorSpace[P].Next;
return P;
}

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים