Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <conio.h>
- #include <string.h>
- char* filename;
- void load_data(char* levelname)
- {
- FILE* level_file;
- char buffer[100];
- char c;
- int test_num;
- int player_y;
- int player_x;
- level_file = fopen(levelname, "r");
- if (level_file == NULL)
- {
- printf("Unable to open file: %s\n", levelname);
- printf("Please check the file actually exists\n");
- exit(EXIT_FAILURE);
- }
- while ((c = fgetc(level_file)) != EOF)
- {
- if (c == '$')
- {
- fscanf(level_file, "%s", buffer);
- if (strcmp(buffer, "test") == 0)
- {
- fscanf(level_file, "%d", &test_num);
- printf("Test number loaded, it is: %d\n", test_num);
- }
- else if (strcmp(buffer, "playerloc") == 0)
- {
- fscanf(level_file, "%d", &player_y);
- fscanf(level_file, "%d", &player_x);
- printf("Player starts at Y: %d and X: %d\n", player_y, player_x);
- }
- else if (strcmp(buffer, "mapdata") == 0)
- {
- while ((c = fgetc(level_file)) != EOF)
- {
- printf("%c", c);
- }
- }
- }
- }
- fclose(level_file);
- }
- void main()
- {
- filename = malloc(12);
- printf("Enter file name:\n");
- scanf("%s", filename);
- printf("\n");
- load_data(filename);
- }
- $test
- 13
- $playerloc
- 6 4
- $mapdata
- WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
- W*W-^-W--------------------------------W
- W-W---W--------------------------------W
- W-WWW----------------------------------W
- W------------------------------------WWW
- W^W-W^^-^------------------------------W
- W------------------------------------WWW
- W-WWW--------------------------------|-W
- W--^---------------------------------WeW
- WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
Add Comment
Please, Sign In to add comment