2013-10-17 66 views
0
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 

這是我的功能,打印10'10'的數組。爲什麼我得到錯誤錯誤:'char'之前的預期表達式?

void drawMap(char map[10][10]){ 
    int i, j; 
    printf("Now drawing map\n"); 
    for(i = 0; i < 10; i++){ 
     for(j = 0; j < 10; j++){ 
      map[i][j] = '.'; 
      printf("%c ", map[i][j]); 
     } 
     printf("\n"); 
    } 
} 

使用上述函數的函數。我在這裏遇到一個錯誤。

void findThecookie(){ 
    drawMap(char map[10][10], int i, int j); 
} 

這是我的主要功能。

int main()  
{ 

    int gamenumber; 
    int randomNumber; 
    int guessednum; 

    printf("Hello and welcome to my babysitting game.\n"); 
    printf("Please select your option. Your choices are:\n"); 
    printf("1) Number guessing game\n" "2) Rock-Paper-Scissors\n" "3) Area of a Random Rectangle\n" "4) Find the Cookie\n" "5) Quit\n"); 
    scanf("%d", &gamenumber); 
    if(gamenumber == 1){ 
     numberGuessing(); 
    } 
    if(gamenumber == 2){ 
     rockPaperscissors(); 
    } 
    if(gamenumber == 3){ 
     randomRectangle(); 
    } 

這裏的另一個錯誤

if(gamenumber == 4){ 
    findThecookie(char map[10][10], int i, int j); 
} 
if(gamenumber == 5){ 
    printf("Exiting the program\n"); 
} 

return 0; 

每次我嘗試編譯我得到的錯誤

project2.c: In function ‘findThecookie’: 
project2.c:22:9: error: expected expression before ‘char’ 
project2.c: In function ‘main’: 
project2.c:171:17: error: expected expression before ‘char’ 

回答

0

有幾件事情你的代碼錯誤:

  1. 同時調用函數你不使用的變量類型。所以,而不是使用findThecookie(char map [10] [10],int j,int i)調用函數。它應該是findThecookie(地圖,j,我)。
  2. findThecookie不期望任何參數,但你試着給它三個。
  3. drawMap確實希望有一個參數,但是你給它三個參數。

閱讀:http://www.tutorialspoint.com/cprogramming/c_functions.htm這是關於使用功能C. 好運基礎教程!

0

drawMap()需要一個參數作爲輸入,但你提供3個參數。

相關問題