我对 C 很陌生,我试图用函数的结果填充文件范围的数组变量,这是一个简单的代码示例来说明我的意思,有人能指出为什么这不起作用的方向吗?
#include <sys/types.h>
#include <dirent.h>
#include <regex.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
static gchar *external_names;
void directories(int arraylength, gchar internal_names[][100]){
int n;
for (n = 0; n < arraylength; n++)
{
strcpy(external_names[n], internal_names[n]);
}
for (n = 0; n < arraylength; n++)
{
printf("%s internal with %s external\n",internal_names[n], external_names[n]);
}
}
void main()
{
gchar anotherarray[10][100];
directories(10, anotherarray);
}
[编辑] 最新代码
#include <sys/types.h>
#include <dirent.h>
#include <regex.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
static gchar *external_names[100];
void directories(int arraylength, gchar internal_names[][100]){
int n = 0;
//gchar external_names[arraylength][100];
for (n = 0; n < arraylength; n++)
{
printf("%s %i\n","before", n);
strcpy(external_names[n], internal_names[n]);
printf("%s %i\n","after", n);
}
}
void main()
{
int n;
gchar anotherarray[10][100];
for (n = 0; n < 10; n++)
{
strcpy(anotherarray[n],"test");
}
directories(10, anotherarray);
for (n = 0; n < 10; n++)
{
printf("%s internal with %s external\n",anotherarray[n], external_names[n]);
}
}