0
입력 파일의 데이터를 구조에 저장하려고하는데 잘못된 작업을 잘 모릅니다. 입력 파일은 다음과 같습니다.입력 파일에서 구조 정보를 읽는 방법
4 2 1 1 3 1
1 1 2 1 3 1
1 1 5 3 1 1
각각의 첫 번째 숫자는 모래로 저장해야하며 두 번째 숫자는 보물로 저장해야합니다.
여기에 지금까지 내 코드입니다 : 내가 복사 타고 무엇이 잘못되었는지보기로 결정 그래서 코드가 너무 잘 보았다#include <stdio.h>
#include <string.h>
#define PIRATES
#define MAP_SIZE 3
//structures
struct pirate {
int dig;
int carry;
};
struct map {
int sand;
int treasure;
};
//functions
int hours_crew();
void scan_file();
//main function
int main() {
FILE * ifp = NULL;
struct map map[MAP_SIZE][MAP_SIZE];
int i, j;
char filename[30];
printf("You have arrived at Treasure Island!\n");
while (ifp == NULL) {
printf("What is the name of your map?\n");
scanf("%s", &filename);
ifp = fopen(filename, "r");
}
for(i=0; i<MAP_SIZE; i++) {
for (j=0; j<MAP_SIZE; j++) {
fscanf(ifp, "%d", &map[i][j].sand);
fscanf(ifp, "%d", &map[i][j].treasure);
}
}
for(i=0; i<MAP_SIZE; i++) {
for (j=0; j<MAP_SIZE*2; j++) {
printf("%d", map[i][j].sand);
printf("%d\n", map[i][j].treasure);
}
}
fclose(ifp);
return 0;
}
'에 대한 (j = 0; j를
예, 그렇습니다. 감사! – Momo
향상된 형식 –