22-11-2006, 16:32
|
|
|
חבר מתאריך: 11.08.05
הודעות: 357
|
|
שמע יש לי בעיה
קודם כל על תתיחסו לשורה של ההקצה בקוד שנתתי אני פשוט לא מצליח לארוף אותו...הוא לא בסדר
את זה תיקנתי
עכשיו לעיניין יש לי בעיה אני לא מצליח להגדיר את העוקן כגלובלי,כי אם תשים לב הפונקציות משתמשות
בעוקן בשביל בדיקה וכאלה.אז ככה שאני לא יכול להגדיר אותו בMAIN אלה כמשתנה גלובלי
אבל כשאני עושה את זה זה עושה לי כמה שגיאות הינה הם
קוד:
--------------------Configuration: connect_list - Win32 Debug--------------------
Compiling...
connect_list.c
G:\my program\connect_list.c(9) : error C2371: 'first_phone' : redefinition; different basic types
G:\my program\connect_list.c(8) : see declaration of 'first_phone'
G:\my program\connect_list.c(9) : warning C4013: 'malloc' undefined; assuming extern returning int
G:\my program\connect_list.c(9) : error C2099: initializer is not a constant
G:\my program\connect_list.c(15) : error C2115: '=' : incompatible types
G:\my program\connect_list.c(27) : warning C4047: '=' : 'struct phonenum *' differs in levels of indirection from 'int '
Error executing cl.exe.
connect_list.exe - 3 error(s), 2 warning(s)
והקוד שלי זה(ואל תגידו לי להחליף את הINT ל MAIN כי זה לא קשור לטעויות)
קוד:
#include<stdio.h>
#include<string.h>
struct phonenum{
char first_name[7],last_name[12],address[22],tel[11];
struct phonenum *nxt_phone;
};
struct phonenum *first_phone;
*first_phone = malloc(sizeof(struct phonenum));
struct phonenum *find_place(char *new_name){
struct phonenum *p,*save;
char found = 0;
for(save = p,p = *first_phone; p && (!found) ;p = p->nxt_phone){
if(strcmp(new_name,p->last_name) < 0)
found = 1;
else
found = 0;
}
return(save);
}
struct phonenum *insert(struct phonenum **after){
struct phonenum *save;
save = *after;
*after = malloc(sizeof(struct phonenum));
if(after != NULL)
(*after)->nxt_phone = save;
return (*after);
}
void add_phone(char *f_nam,char *l_nam,char *address,char *tel){
struct phonenum *p;
p = find_place(l_nam);
if(p == first_phone)
p = insert(&first_phone);
else
p = insert(&(p->nxt_phone));
strcpy(p->first_name,f_nam);
strcpy(p->last_name,l_nam);
strcpy(p->address,address);
strcpy(p->tel,tel);
}
void main(){
getch();
}
|