2017-05-23 4 views
-1

나는 2dim 문자 구조체의 멤버로 입력을 읽기 위해 노력하고있어에서C 2 차원 숯불 구조체

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

enum { HIGHT=14, WIDTH=147, IMAGES=24 }; 

typedef struct{ 
    char *frame[HIGHT][WIDTH]; 
    int fps; 
} frame_stack_t; 

void out(frame_stack_t *frame_stack[IMAGES]); 

int main(){ 
    frame_stack_t *frame_stack[IMAGES]; 

    for (int i=0; i<IMAGES; i++){ 
     for (int j=0; j<HIGHT; j++){ 
      strcpy(frame_stack[i]->frame[j], "some text"); 
     } 
    } 

    out(frame_stack); 
} 

void out(frame_stack_t *frame_stack[IMAGES]){ 
    for (int i=0; i<IMAGES; i++){ 
     for (int j=0; j<HIGHT; j++){ 
      printf("%s",frame_stack[i]->frame[j]); 
     } 
    } 
} 

그것은 바로 내 보이지만, 나는 다음과 같은 출력 받아 봐 :

test_struct.c: In function ‘main’: 
test_struct.c:19:25: warning: passing argument 2 of ‘strcpy’ from incompatible pointer type [-Wincompatible-pointer-types] 
    strcpy("some text", frame_stack[i]->frame[j]); 
         ^
In file included from test_struct.c:3:0: 
/usr/include/string.h:125:14: note: expected ‘const char * restrict’ but argument is of type ‘char **’ 
extern char *strcpy (char *__restrict __dest, const char *__restrict __src) 
      ^
test_struct.c: In function ‘out’: 
test_struct.c:29:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat=] 
    printf("%s",frame_stack[i]->frame[j]); 
     ^
Speicherzugriffsfehler 

을 GDB가 말해 함께 그 strcpy와는

Program received signal SIGSEGV, Segmentation fault. 
__strcpy_sse2_unaligned() at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:546 
546 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: Datei oder Verzeichnis nicht gefunden. 

사람이 무슨 잘못 여기 말해 주시겠습니까 실패?

+1

char 포인터 배열 배열이 있습니다. 배열을 인덱싱하면 char 포인터 배열이 아닌 char 포인터 배열을 얻을 수 있습니다. –

+1

질문하기 전에 적어도 수동 읽기를 수행하십시오. 예를 들어, 당신의'strcpy()'인자가 잘못된 방법으로 주위에 –

+0

쓰레드를 다시 섞어서 새로운 오류를 게시했습니다. – Bubblepop

답변

0

문제의 C 코드에는 많은 문제가 있습니다. 이와 같은 공개 토론회에 질문을 올리기 전에 독서와 연습을 해보십시오. 아래의 수정 된 코드를보고 이해를 시도하십시오.

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

enum { HIGHT=14, IMAGES=24, WIDTH=147 }; 

typedef struct{ 
char frame[HIGHT][WIDTH]; 
int fps; 
} frame_stack_t; 

void out(frame_stack_t *frame_stack); 

int main() 
{ 
frame_stack_t frame_stack[IMAGES]; 
int i, j; 

for (i=0; i<IMAGES; i++) 
{ 
    for (j=0; j<HIGHT; j++) 
    { 
     strcpy(frame_stack[i].frame[j], "some text\n"); 
    } 
} 

out(frame_stack); 
} 

void out(frame_stack_t frame_stack[]) 
{ 
int i,j; 
for (i=0; i<IMAGES; i++) 
{ 
    for (j=0; j<HIGHT; j++) 
    { 
     printf("%s",frame_stack[i].frame[j]); 
    } 
} 
} 
+0

무슨 문제입니까? 옆에있는 문제는 내가 잘 실행되는 코드를 게시 설명했다. – Bubblepop