메신저 꽤 새로운 C, 그리고 파일의 넓은 배열 변수를 함수의 결과로 채우려 고 메신저 간단한 코드 샘플 heres 내 말은, 사람이 방향으로 나를 가리킬 수 있습니다 heres 이게 왜 효과가없는거야?캔트 파일 변수에 값을 할당
#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]);
}
}
포인터를 통해 메모리의 불확정 주소에 쓰고 있습니다. 파일이 아닙니다. ['fopen()'] (http://en.cppreference.com/w/c/io/fopen), ['fprintf()'] (http : //)로 시작하는 C 런타임 라이브러리 FILE apis 형식을 사용하십시오. /en.cppreference.com/w/c/io/fprintf), ['fwrite()'] (http://en.cppreference.com/w/c/io/fwrite) 등이 있습니다. 네가 시작 했어. – WhozCraig
변수 값을 지정할 때까지 변수 값을 사용할 수 없습니다. 어떤 값을 할당하기 전에'external_names' (이 코드에서는'strcpy (external_names [n], internal_names [n]);')를 사용합니다. –
내부 배열의 값을 지정하지 않고 'strcpy (external_names [n], internal_names [n]);) 파일에 파일을 쓰지 않으려 고합니다. – Mike