I wrote this very simple program to make sure I understood arrays of structures and file i/o. When I comple, I get an error on line 28 that states 'passing arg 2 to function strcpy create pointer without cast). I has gotten this error in a simpler version (sans structures) and was rid of it by declaring the function as:
Now, however, the same fix isn't working. Any insight would be appreciated. The program is meant to read in a text file of 5 rows, each with 5 symbols. It creates a structure with their symbol and location, and then spits it back out.Code:char blah[5];
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct wildroom{ int x; int y; char symbol[1]; } wr; int main(){ FILE *minimap; wr wilddata[24]; int x,y; minimap = fopen("./minimap.txt","r"); if(minimap==NULL) { printf("Error in File Read\n"); exit(0); } for(x=0;x<5;x++){ for(y=0;y<5;y++){ wilddata[(x*5)+y].x=x; wilddata[(x*5)+y].y=y; strcpy(wilddata[(x*5)+y].symbol,fgetc(minimap)); } } for(x=0;x<5;x++){ for(y=0;y<5;y++){ printf("%s",wilddata[(x*5)+y].symbol); } printf("\n"); } fclose(minimap); return(1); }



LinkBack URL
About LinkBacks




