   Finding the height and width of a map read from a file.
  woah long topic. Ok here''s my problem, i have a file thats 22by10, in my program the height and width of the file is essential for collision detection, however what I am attempting to build it a basic maze engine, so i can''t be bothered by counting my file lengths and widths EVERYTIME i want to make a new level or something like that, so I thought that making a function that gets the map height then another that gets the width would be a good idea. But i have NO IDEA HOW!!!Any ideas? 
  First line in your map file:5 10[data...]Then you can read the first two variables as width = 5 and height = 10. ;  If your map file is text based (e.g. you type it in using notepad), you could find the width by counting the characters until a newline (\n or \r\n), and the height by the number of lines in the file. // assuming hFile = opened map filechar szBuf[256];fgets(szBuf, 256, hFile);char *pScan = &szBuf[0];while(*pScan && *pScan != '\r' && *pScan != '\n') pScan++;int nWidth = pScan - &szBuf[0];int nHeight = 1;while(!ferror(hFile) && !feof(hFile) && fgets(szBuf, 256, hFile))   nHeight++;// Now seek back to the start of the file and read in the map data. ____________ride the sainted rhythms on the midnight train to romford [edited by - mattd on February 3, 2004 3:18:05 PM];  does your game read in a mapfile and replace corresponding characters with in game data? for example, is your map.txt file look like thisxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxetc? where x is a wall and 0 is an open space? if so, just do what lloyd above saidhave the first 2 numbers of the map file be the legth and width of the mapso you would do file_in>>legth   file_in>>width, then you would multiply legth*width to get the size of the map, thenx = 0; (a counter for how far along the x axis youve moved)y = 0; (a counter how far along the y axis youve moved)while (!y == height) (keep reading in characters untill you have reached the end of the map){file_in>>tempif temp == 0{put an empty space in your map in that spot{else if temp == x{put a wall in your map in that spot;}(if ++x == width) (increment x untill its the width of the map, then we know to go down the next row)y++ ; (move down a row and start at the next row)x = 0; (reset this row to 0)ps check out gametutorials.com its where i learned how to do this they have good example code for this topic [edited by - graveyard filla on February 3, 2004 3:41:40 PM] [edited by - graveyard filla on February 3, 2004 3:46:05 PM]