私は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]);
}
}