我写了一个小程序,我无法将二维数组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 –
编译结果 - 行 –