Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMrPhoenix

Posted 21 January 2013 - 01:21 AM

This is the file 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>

    typedef struct {
        char map_title[68];
        int width,height;
        char map_tiles[100][100];
    } map_file;


    char *readFile(char *fileName) {
      FILE *file;
      char *code = malloc(1000 * sizeof(char));
      char *p = code;
      file = fopen(fileName, "r");
      do
      {
        *p++ = (char)fgetc(file);
      } while(*p != EOF);
      *p = '\0';
      return code;
    }

    map_file *load_map(char *location) {
        printf("Loading map : %s \n", location);

        map_file *tehMap;
        char *dataToken,*map_data;

        map_data = readFile(location);

            dataToken = strtok(map_data,",");

            printf("STARTED TOKEN OUTPUT\n");
            while(dataToken != NULL) {
                printf("TOKEN : %s \n",dataToken);
                dataToken = strtok(NULL,",");
            }
            printf("FINISHED TOKEN OUTPUT\n");


        return tehMap;
    }


int main()
{
    printf("Map engine testing ground for logic\n\n");

    map_file *theMap;
    theMap = load_map("map.txt"); // i plan on using the function to assign the values from the file to the struct

    return 0;
}

 

 and ill attach map.map so you have something to test with, but my issue is in stdout only like half of the map file is output im not sure if it a char error of something in the strtok function.

 

any tips or help would be mean a lot, thank you for your time smile.png


#1MrPhoenix

Posted 21 January 2013 - 01:20 AM

This is the file 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>

    typedef struct {
        char map_title[68];
        int width,height;
        char map_tiles[100][100];
    } map_file;


    char *readFile(char *fileName) {
      FILE *file;
      char *code = malloc(1000 * sizeof(char));
      char *p = code;
      file = fopen(fileName, "r");
      do
      {
        *p++ = (char)fgetc(file);
      } while(*p != EOF);
      *p = '\0';
      return code;
    }

    map_file *load_map(char *location) {
        printf("Loading map : %s \n", location);

        map_file *tehMap;
        char *dataToken,*map_data;

        map_data = readFile(location);

            dataToken = strtok(map_data,",");

            printf("STARTED TOKEN OUTPUT\n");
            while(dataToken != NULL) {
                printf("TOKEN : %s \n",dataToken);
                dataToken = strtok(NULL,",");
            }
            printf("FINISHED TOKEN OUTPUT\n");


        return tehMap;
    }


int main()
{
    printf("Map engine testing ground for logic\n\n");

    map_file *theMap;
    theMap = load_map("map.txt");

    return 0;
}

 

 and ill attach map.map so you have something to test with, but my issue is in stdout only like half of the map file is output im not sure if it a char error of something in the strtok function.

 

any tips or help would be mean a lot, thank you for your time :)


PARTNERS