error שלא הצלחתי לפתור

lillitush

New member
error שלא הצלחתי לפתור

error C2059: syntax error : ']' בקוד הבא: for (i=0;i<x;i++) for(j=0;j<y;j++) { if ((i==0)&&(j==0)) matrix[j]=1; else { printf("please enter value 1 or 0 to matrix[%d][%d]",i,j); scanf("%d",&matrix[j]); } } print_matrix(matrix[] [col],x,y); } void print_matrix(int matr[][col],int line_num,int col_num) { זה קורה בשורת הקריאה לפונקציה.
 

annefan

New member
יישור קוד! יישור קוד!

לפני הקוד לוחצים על [_תחילת_קוד_] ואחריו על [_סיום_קוד_], שניהם מתחת לחלון של ההודעה.
 

galh

New member
כמה דברים...

1. תשתמשי בכפתורים "תחילת קוד" ו- "סיום קוד" כאשר מצרפים קוד. 2. אי אפשר להעביר פרמטר של מערך דו מימדי בלי לקבוע את הגודל. אפשר אחת משתי הצורות הבאות:
void print_matrix(int mat[ROW][COL]); void print_matrix(int mat[ROW][]);​
כלומר, הגודל חייב להיות קבוע (מקרה ראשון), או גודל דינמי, אבל רק בחלק של ה"עמודה".
 

lillitush

New member
אוקיי

לא ידעתי על התחילת קוד וסיום קוד.בכל אופן הבעיה שברגע שאהי מוסיף גדלים קבועים לשני הפרמטרים הקומפיילר מציין error C2660: 'print_matrix' : function does not take 3 parameters
 

galh

New member
תראי את הקוד (עם "תחילת קוד" ../images/Emo3.gif).

 

lillitush

New member
הקוד

//this program finds the shortest route #include <stdio.h> # define rows 50 #define col 50 void print_matrix(int); void main() { int i,j,x,y; printf("pleae enter the sizes of the matrix\n"); scanf("%d,%d",&x,&y);//x-rows,y,columns int matrix[rows][col]; for (i=0;i<x;i++) for(j=0;j<y;j++) { if ((i==0)&&(j==0)) matrix[j]=1; else { printf("please enter value 1 or 0 to matrix[%d][%d]",i,j); scanf("%d",&matrix[j]); } } print_matrix(matrix[rows] [col],x,y); } void print_matrix(int matr[rows][col],int line_num,int col_num) { int a,b; for (a=0;a<line_num;a++) for(b=0;b<col_num;b++) { printf("%d\t",matr[a]); if (b==col_num) printf("\n"); } }
 

galh

New member
תסתכלי למעלה...

יש הצהרה על הפונקציה print_matrix שמקבלת רק פרמטר אחד וזה לא תואם למימוש של הפונקציה שמקבלת שלוש פרמטרים. טיפ: שמגדירים "קבועים" עדיף לקרוא להם משם שמורכב מאותיות גדולות בלבד בשביל הפרדה "ויזואלית" בשבילך, כלומר ROW ו- COL ולא row ו- col.
 

lillitush

New member
אני מצטער להציק

אבל אני כנראה לא יודע להעביר מערך דו מימדי לפונקציה.
//this program finds the shortest route #include <stdio.h> # define rows 50 #define col 50 void print_matrix(int matr[rows][col],int line_num,int col_num) { int a,b; for (a=0;a<line_num;a++) for(b=0;b<col_num;b++) { printf("%d\t",matr[a]); if (b==col_num) printf("\n"); } } void main() { int i,j,x,y; printf("pleae enter the sizes of the matrix\n"); scanf("%d,%d",&x,&y);//x-rows,y,columns int matrix[rows][col]; for (i=0;i<x;i++) for(j=0;j<y;j++) { if ((i==0)&&(j==0)) matrix[j]=1; else { printf("please enter value 1 or 0 to matrix[%d][%d]",i,j); scanf("%d",&matrix[j]); } } print_matrix(matrix[rows] [col],x,y); }

ואז זה נותן לי הודעת שגיאה הבאה: error C2664: 'print_matrix' : cannot convert parameter 1 from 'int' to 'int [][50]' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.
 

galh

New member
לא לדאוג, לומדים.

קוראים לפונקציה בצורה הבאה:
print_matrix(matrix, x, y);​
כדאי שתקרא שוב את הקטע של מערכים בספר.
 
למעלה