【发布时间】:2013-05-12 09:19:37
【问题描述】:
我写了一个小程序,我无法将二维数组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]
【问题讨论】:
-
一般来说,发布代码产生的错误总是好的。这样更容易提供帮助。
-
这是一个全面的答案:stackoverflow.com/a/8767247/1837457
-
编译结果-OK
-
执行错误
bash: string 1: 32447 error of segmentation (ready dump core) '/home/rem/projects/development/cpp_test/1' -
在完整代码上添加我帖子的链接。