我寫了一個小程序,我無法將二維數組words[10][max_row_size]
傳遞給函數notify
。如果可以,請你幫助我。
附帶代碼的一部分。
如何將二維數組傳遞到函數
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string.h>
#include <unistd.h>
using namespace std;
#define max_row_size 100
int notify(char words[max_row_size]);
int main(void) {
ifstream dictionary("dictionary.txt");
//ditrionary looks like
//hello-world
//universe-infinity
//filename-clock
string s;
int i=0;
char words[10][max_row_size];
while(!dictionary.eof()){
dictionary>>s;
strcpy(words[i++],s.c_str());
}
notify(words[max_row_size]);
return 0;
}
int notify(char words[max_row_size]){
cout<<words[1];
return 0;
}
It is a full code of my programm, may be it can help you
這是一個錯誤
/home/rem/projects/github/notify_words/notify_words.cpp: В функции «int notify(int, char*)»:
/home/rem/projects/github/notify_words/notify_words.cpp:65:113: предупреждение: format «%s» expects argument of type «char*», but argument 3 has type «int» [-Wformat]
一般情況下,它總是好發佈你的代碼產生的錯誤。這樣可以更容易地提供幫助。 – Simon
這裏是一個全面的答案:http://stackoverflow.com/a/8767247/1837457 –
編譯結果 - 行 –