-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.
사람이 무슨 잘못 여기 말해 주시겠습니까 실패?
char 포인터 배열 배열이 있습니다. 배열을 인덱싱하면 char 포인터 배열이 아닌 char 포인터 배열을 얻을 수 있습니다. –
질문하기 전에 적어도 수동 읽기를 수행하십시오. 예를 들어, 당신의'strcpy()'인자가 잘못된 방법으로 주위에 –
쓰레드를 다시 섞어서 새로운 오류를 게시했습니다. – Bubblepop