Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [a5] creating, editing File!

This thread is locked; no one can reply to it. rss feed Print
[a5] creating, editing File!
Jefferson Almeida
Member #12,659
March 2011

I can open a file in the allegro that was saved by the console program, or I have to create it with "File system routines."

My idea is adding that "void test..." in an "int main" for example.

int main(int... {
// load allegro ini..
test();
graphics();
display = al_create_display(SCREEN_W, SCREEN_H);
....

It's possible?

#SelectExpand
1void test() { 2 bool go = false; 3 FILE *arq; 4 printf("Isometric Map Editor\n"); 5 printf("Select\n"); 6 printf("[1] New Map\n"); 7 printf("[2] Edit Map\n"); 8 int resp; 9 scanf("%d",&resp); 10 if(resp==1) { 11 while (go == false) { 12 printf("Enter a name for your map (max 20)\n"); 13 fflush(stdin); 14 gets(map_name); 15 printf("Enter a size N for your map ( N x N ) max 50\n"); 16 fflush(stdin); 17 scanf("%d",&resp); 18 if(resp <50 && resp>0) m_siz = resp; 19 else printf("Can not create a map size %d, therefore I will create (15 x 15)\n", resp); 20 strcpy(directory, "data/map/"); 21 strcat(directory, map_name); 22 strcat(directory, ".map"); 23 printf("creating: %s\n", directory); 24 25 if(!fopen(directory,"r")) { 26 arq=fopen(directory,"w+"); 27 go = true; 28 printf("Map created\n"); 29 system("pause"); 30 fclose(arq); 31 } 32 else printf("Error!(Try other name)\n"); 33 } 34 } 35 else if(resp==2) { 36 printf("Type the name of your map\n"); 37 fflush(stdin); 38 gets(map_name); 39 strcpy(directory, "data/map/"); 40 strcat(directory, map_name); 41 strcat(directory, ".map"); 42 printf("\n opening file '%s'\n", directory); 43 if(fopen(directory, "r")) { 44 arq = fopen(directory, "r"); 45 fread(&savemap, sizeof(struct mapdata), 1, arq); 46 for(int z = 0 ; z < 3; z++) { 47 for(int y = 0 ; y < m_siz ; y++) { 48 for(int x = 0 ; x < m_siz ; x++) { 49 map[z][x][y] = savemap.mapdat[z][x][y]; 50 } 51 } 52 } 53 strcpy(map_name, savemap.name); 54 m_siz = savemap.m_size; 55 for(int c_layer=0; 56 c_layer< l_size; 57 c_layer++) { 58 layers[c_layer].layer = savemap.m_layers[c_layer].layer; 59 } 60 fclose(arq); 61 printf("File opening... !\n"); 62 system("pause"); 63 64 } 65 else 66 printf("Error... Could not find on the map %s\n", map_name); 67 } 68};

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: