Example #1
0
void createBoardArray(BoardNode newBoard)	{

	int row, col;

    newBoard->board = (buttonState**) checkMalloc(malloc(MAXROW * sizeof(buttonState*)));

    for(row = 0; row < MAXROW; row++)   {
        newBoard->board[row] = (buttonState*) checkMalloc(malloc(MAXCOL*sizeof(buttonState)));
        for(col = 0; col < MAXCOL; col++)   {
            newBoard->board[row][col] = DEAD;
        }
    }		

}
Example #2
0
void reverseStrandC(vector *r_C, vector *s_C, vector *r_C1, vector *s_C1) {

  r_C->n  = s_C->n; r_C1->n = s_C1->n;

  r_C->vector   = (unsigned int*)malloc(r_C->n * sizeof(unsigned int));
  checkMalloc(r_C->vector,  "reverseStrandC");
  r_C1->vector  = (unsigned int*)malloc(r_C1->n * sizeof(unsigned int));
  checkMalloc(r_C1->vector,  "reverseStrandC");

  r_C->vector[0] = s_C->vector[3]; r_C1->vector[0] = s_C1->vector[3];
  r_C->vector[3] = s_C->vector[0]; r_C1->vector[3] = s_C1->vector[0];
  r_C->vector[1] = s_C->vector[2]; r_C1->vector[1] = s_C1->vector[2];
  r_C->vector[2] = s_C->vector[1]; r_C1->vector[2] = s_C1->vector[1];

}
Example #3
0
/*
 * creates empty board structure
 */
BoardNode createBoard(BoardNode ParentBoard)	{

	BoardNode newBoard = (BoardNode) checkMalloc(malloc(sizeof(*newBoard)));
	populateBoard(newBoard,ParentBoard);
	return newBoard;

}
Example #4
0
void readUIntVector(vector *vector, const char *directory, const char *name) {

  size_t err=0;
  FILE *fp;

  char path[500];
  path[0]='\0';
  strcat(path, directory);
  strcat(path, "/");
  strcat(path, name);
  strcat(path, ".vec");

  fp  = fopen(path,  "rb+");
  checkFileOpen(fp, path);

  err = fread(&vector->n, sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  vector->vector = (unsigned int *) malloc(vector->n * sizeof(unsigned int));
  checkMalloc(vector->vector, path);

  err = fread(vector->vector, sizeof(unsigned int), vector->n, fp);
  checkFileRead(err, vector->n, path);

  fclose(fp);

}
Example #5
0
MazeMap createMap(int height, int width)	{

	int i;
	if((height > 0) && (width > 0))	{
		MazeMap newMaze = (MazeMap) checkMalloc(malloc(sizeof(*newMaze)));
		newMaze->mazeGrid = (struct mazeBlock**) checkMalloc(malloc(height * sizeof(struct mazeBlock*)));
		for(i = 0; i < width; i++)	{
			newMaze->mazeGrid[i] = (struct mazeBlock*) checkMalloc(malloc(width * sizeof(struct mazeBlock)));	
		}
		newMaze->height = height;
		newMaze->width = width;
		return newMaze;
	} else {
		fprintf(stderr, "No dimensions given for map size in first line of input file\n");	
		exit(1);
	}
}
Example #6
0
PMERGEREC createMergeRec(PCHAR sourceName,PCHAR targetName)
{
	PMERGEREC rec=(PMERGEREC)checkMalloc(sizeof(MERGEREC));

	rec->sourceName=checkStrdup(sourceName);
	rec->targetName=checkStrdup(targetName);
	return rec;
}
Example #7
0
PTree newPTree (int boardSize) {

    PTree p = malloc (sizeof (pTree));
    checkMalloc (p);
    p->boardSize = boardSize;
    p->root = newNode (boardSize);

    return p;
}
Example #8
0
/*
 * Creates new queue
 */
void createQueue()	{

	BoardQueueHead newQueue = (BoardQueueHead) checkMalloc(malloc(sizeof(*newQueue)));
	newQueue->targetRow = '\0';
	newQueue->targetCol = '\0';
	newQueue->start = NULL;
	newQueue->start = NULL;
	newQueue->nItems = 0;
	newQueue->finalBoard = NULL;
	newQueue->runMode = LINEAR;
	getQueue(newQueue);
}
Example #9
0
/**
* Create a string representation of a given multi-precision integer
*
* @param s destination pointer
* @param mp the number to represent
* @param base Output the string representation in this base
*/
void static fhe_mp_to_string(char **s, mp_int *mp, int base) {
    int size;	// is int, not size_t; this is how libtommath wants it

    // libtommath documentation says that the maximum base is 64; base < 2 does
    // not make sense.  (Actually, base 1 makes sense, but nobody seems to
    // agree with me on that one.)
    assert(base > 1 && base <= 64);

    /* Allocate space and generate ASCII representation of private key */
    (void)mp_radix_size(mp, 0x10, &size);
    *s = (char *)checkMalloc(size);
    (void)mp_toradix(mp, *s, 0x10);
}
Example #10
0
/*
 *Adds and initializes list members.
 */
void addNode(PathList list, int addRow, int addCol) {

    if(list->start == NULL) {
        list->start = list->current = (PathNode) malloc(sizeof(*(list->start)));
    } else {
        list->current->next = (PathNode) checkMalloc(malloc(sizeof(*(list->current->next))));
        list->current = list->current->next;
    }

    list->current->row = addRow;
    list->current->col = addCol;
    list->current->next = NULL;
    list->nItems++;
}
Example #11
0
int s7( int suite, int weight, int argc, char *argv[] ) {
    START_SUITE( suite, "freeGpFile", weight, NUM_POS_TESTS, NUM_NEG_TESTS );

    START_POS_TEST( 1, "Test freeGpFile doesn't blow up" );

    GpFile fp;

    fp.dateFormat = strdup( GP_DATEFORMAT );
    fp.nwaypts = 2;
    fp.waypt = checkMalloc( sizeof( GpWaypt ) * fp.nwaypts );

    fp.waypt[0].ID = strdup( "ID1" );
    fp.waypt[0].symbol = strdup( "SYMBOL1" );
    fp.waypt[0].comment = strdup( "COMMENT1" );

    fp.waypt[1].ID = strdup( "ID2" );
    fp.waypt[1].symbol = strdup( "SYMBOL2" );
    fp.waypt[1].comment = strdup( "COMMENT2" );

    fp.nroutes = 3;

    GpRoute r;
    fp.route = checkMalloc( sizeof( GpRoute * ) * fp.nroutes );
    fp.route[0] = checkMalloc( sizeof( GpRoute ) + sizeof( r.leg[0] ) );
    fp.route[0]->npoints = 1;
    fp.route[0]->comment = strdup( "TEH COMMENHT1" );
    fp.route[1] = checkMalloc( sizeof( GpRoute ) + sizeof( r.leg[0] ) * 2 );
    fp.route[1]->npoints = 2;
    fp.route[1]->comment = strdup( "TEH COMMENHT2" );
    fp.route[2] = checkMalloc( sizeof( GpRoute ) + sizeof( r.leg[0] ) * 3 );
    fp.route[2]->npoints = 3;
    fp.route[2]->comment = strdup( "TEH COMMENHT3" );

    fp.ntrkpts = 1;
    fp.trkpt = checkMalloc( sizeof( GpTrkpt ) * fp.ntrkpts );
    fp.trkpt[0].segFlag = 1;
    fp.trkpt[0].comment = strdup( "A COMMENT" );

    int exception;

    try {
        freeGpFile( &fp );
    } catch ( exception ) {
        LOG( "%s\n", Exception_Names[exception] );
        FAIL_POS_TEST
    }

    PASS_POS_TEST

    END_SUITE
}
Example #12
0
void readCompMatrix(comp_matrix *matrix, const char *directory, const char *name) {

  size_t err=0;
  FILE *fp;

  char path[500];

  path[0]='\0';
  strcat(path, directory);
  strcat(path, "/");
  strcat(path, name);
  strcat(path, ".desp");

  fp  = fopen(path,  "rb+");
  checkFileOpen(fp, path);

  err = fread(&matrix->siz,      sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  err = fread(&matrix->n_desp,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  err = fread(&matrix->m_desp,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  for (size_t i=0; i<matrix->n_desp; i++) {
    matrix->desp[i] = (unsigned int *) malloc(matrix->m_desp * sizeof(unsigned int));
    checkMalloc(matrix->desp[i], path);
    err = fread(matrix->desp[i], sizeof(unsigned int), matrix->m_desp, fp);
    checkFileRead(err, matrix->m_desp, path);
  }

  fclose(fp);

#if defined VECTOR_O_32BIT_COMPRESSION

  path[0]='\0';
  strcat(path, directory);
  strcat(path, "/");
  strcat(path, name);
  strcat(path, ".count");

  fp  = fopen(path,  "rb+");
  checkFileOpen(fp, path);

  err = fread(&matrix->n_count,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  err = fread(&matrix->m_count,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  for (size_t i=0; i<matrix->n_count; i++){
    matrix->count[i] = (unsigned int *) malloc(matrix->m_count * sizeof(unsigned int));
    checkMalloc(matrix->count[i], path);
    err = fread(matrix->count[i], sizeof(unsigned int), matrix->m_count, fp);
    checkFileRead(err, matrix->m_count, path);
  }

  fclose(fp);

#elif defined VECTOR_O_64BIT_COMPRESSION

  path[0]='\0';
  strcat(path, directory);
  strcat(path, "/");
  strcat(path, name);
  strcat(path, ".count");

  fp  = fopen(path,  "rb+");
  checkFileOpen(fp, path);

  err = fread(&matrix->n_count,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  err = fread(&matrix->m_count,   sizeof(size_t),  1, fp);
  checkFileRead(err, 1, path);

  for (size_t i=0; i<matrix->n_count; i++){
    matrix->count[i] = (unsigned long long *) malloc(matrix->m_count * sizeof(unsigned long long));
    checkMalloc(matrix->count[i], path);
    err = fread(matrix->count[i], sizeof(unsigned long long), matrix->m_count, fp);
    checkFileRead(err, matrix->m_count, path);
  }

  fclose(fp);

#endif

}
Example #13
0
/*
 *Creates space to stored start of list.
 */
PathList createList()   {

    PathList NewList = (PathList) checkMalloc(malloc(sizeof(*NewList)));
    NewList->start = NewList->current = NULL;
    return NewList;
}
Example #14
0
int main(int argc, char *argv[])
{
    int count, tmpNum, i, j, len, m;
    char *strings, *indexJ, *indexJ1, *tmp;

    srand((unsigned int) time(NULL));

    if (argc != 2) {
        printf("Aufruf: java Stringsort Anzahl");
        return 1;
    }

    count = atoi(argv[1]);
    m = strlen(argv[1]) + 1;

    strings = (char*) calloc(count * m, sizeof(char));

    tmp = (char*)  calloc(m, sizeof(char));

    if (checkMalloc(strings) == 1) return 1;
    if (checkMalloc(tmp) == 1) return 1;

    printf("Unsortiertes Feld: \n");
    for (i = 0; i < count; ++i) {
        tmpNum = rand() % count;
        sprintf(tmp, "%d", tmpNum);
        printf("%s ", tmp);
        memcpy(strings + (m * i), tmp, strlen(tmp) + 1);
    }

    for (i = count; i > 1; i--) {
        for (j = 0; j < i - 1; ++j) {
            indexJ = strings + j * m;
            indexJ1 = strings + (j + 1) * m;

            if (strcmp(indexJ, indexJ1) > 0) {
                memcpy(tmp, indexJ1, strlen(indexJ1) + 1);
                memcpy(indexJ1,  indexJ, strlen(indexJ) + 1);
                memcpy(indexJ, tmp, strlen(tmp) + 1);
            }
        }
    }


    printf("\nSortiertes Feld: \n");

    len = 1;
    for (i = 0; i < count; i++) {
        len += (strlen(strings + i *m) + 1);
    }


    free(tmp);
    tmp = NULL;

    tmp = (char*) calloc(len, sizeof(char));
    if (checkMalloc(tmp) == 1) return 1;


    strcat(tmp, strings);
    indexJ = strings;
    for (i = 1; i < count; ++i) {
        if (strcmp(indexJ, indexJ + m) == 0) {
            strcat(tmp, "*");
        } else {
            strcat(tmp, " ");
            strcat(tmp, indexJ + m);
        }
        indexJ += m;
    }


    printf(tmp);
    printf("\n");

    free(tmp);
    free(strings);
    return 0;
}
Example #15
0
void load_reference(byte_vector *X, int duplicate, exome *ex, const char *path) {

  FILE *ref_file;
  ref_file = fopen(path,  "r");
  checkFileOpen(ref_file, path);

  size_t read=0, size;
  unsigned int nX;

  fseek(ref_file, 0, SEEK_END);
  read = ftell(ref_file);
  fseek(ref_file, 0, SEEK_SET);

  if (duplicate) size = 2*read + 1000;
  else           size = read + 1000;

  X->vector = (char *) malloc( size * sizeof(char) );
  checkMalloc(X->vector, path);

  nX=0;
  if (ex !=NULL) ex->size=0;

  //char line[MAXLINE];
  unsigned int length, partial_length, total_length;

  total_length=0;
  partial_length=0;

  while ( fgets(X->vector + total_length, MAXLINE, ref_file) ) {

    if ( (X->vector + total_length)[0] == '>') {

      if (ex!=NULL) {

	if (total_length == 0) {

	  sscanf(X->vector + total_length, ">%s ", ex->chromosome + ex->size * IDMAX);
	  ex->start[ex->size] = 0;

	} else {

	  ex->end[ex->size] = partial_length - 1;
	  partial_length=0;

	  if (ex->size==0)
	    ex->offset[0] = 0;
	  else
	    ex->offset[ex->size] = ex->offset[ex->size-1] + (ex->end[ex->size-1] - ex->start[ex->size-1] + 1);
	  ex->size++;

	  sscanf(X->vector + total_length, ">%s ", ex->chromosome + ex->size * IDMAX);
	  ex->start[ex->size] = 0;

	}

      }

      continue;

    }

    length = strlen(X->vector + total_length);
    if ((X->vector + total_length)[length-1]=='\n')
      length--;

    partial_length += length;
    total_length += length;

  }

  if (ex != NULL) {
    ex->end[ex->size] = partial_length - 1;
    partial_length=0;
    
    if (ex->size==0)
      ex->offset[0] = 0;
    else
      ex->offset[ex->size] = ex->offset[ex->size-1] + (ex->end[ex->size-1] - ex->start[ex->size-1] + 1);
    ex->size++;
  }

  replaceBases(X->vector, X->vector, total_length);

  X->vector[total_length] = DDD;
  X->n = total_length;

  fclose(ref_file);

  if (duplicate) duplicate_reference(X);

}
Example #16
0
File: util.c Project: nmlgc/alink
BOOL getStub(PCHAR stubName,PUCHAR *pstubData,UINT *pstubSize)
{
	FILE *f;
	unsigned char headbuf[EXE_HEADERSIZE];
	PUCHAR buf;
	UINT imageSize;
	UINT headerSize;
	UINT relocSize;
	UINT relocStart;
	int i;

	if(stubName)
	{
		f=fopen(stubName,"rb");
		if(!f)
		{
			addError("Unable to open stub file %s",stubName);
			return FALSE;
		}
		/* try and read EXE header */
		if(fread(headbuf,1,EXE_HEADERSIZE,f)!=EXE_HEADERSIZE)
		{
			addError("Error reading from file %s",stubName);
			return FALSE;
		}
		if((headbuf[EXE_SIGNATURE]!=0x4d) || (headbuf[EXE_SIGNATURE+1]!=0x5a))
		{
			addError("Stub not valid EXE file");
			return FALSE;
		}
		/* get size of image */
		imageSize=headbuf[EXE_NUMBYTES]+(headbuf[EXE_NUMBYTES+1]<<8)+
			((headbuf[EXE_NUMPAGES]+(headbuf[EXE_NUMPAGES+1]<<8))<<9);
		if(imageSize%512) imageSize-=512;
		headerSize=(headbuf[EXE_HEADSIZE]+(headbuf[EXE_HEADSIZE+1]<<8))<<4;
		relocSize=(headbuf[EXE_RELCOUNT]+(headbuf[EXE_RELCOUNT+1]<<8))<<2;
		imageSize-=headerSize;

		/* allocate buffer for load image */
		buf=(PUCHAR)checkMalloc(imageSize+0x40+((relocSize+0xf)&0xfffffff0));
		/* copy header */
		for(i=0;i<EXE_HEADERSIZE;i++) buf[i]=headbuf[i];

		relocStart=headbuf[EXE_RELOCPOS]+(headbuf[EXE_RELOCPOS+1]<<8);
		/* load relocs */
		fseek(f,relocStart,SEEK_SET);

		if(relocSize)
		{
			if(fread(buf+0x40,1,relocSize,f)!=relocSize)
			{
				addError("Error reading from file %s",stubName);
				return FALSE;
			}
			/* paragraph align reloc size */
			relocSize+=0xf;
			relocSize&=0xfffffff0;
		}

		if(relocSize || (imageSize>0x1c))
		{
			/* new header is 4 paragraphs long + relocSize*/
			relocSize>>=4;
			relocSize+=4;
		}
		else
		{
Example #17
0
static BOOL COFFLibLoad(PFILE libfile,PMODULE mod,BOOL isDjgpp)
{
	UINT i,j;
	UINT numsyms;
	UINT modpage;
	UINT memberSize;
	UINT startPoint;
	PUCHAR endptr;
	PCHAR name;
	PUCHAR modbuf;
	PUCHAR longnames;
	PPSYMBOL symlist;
	INT x;
	UCHAR buf[60];

	startPoint=ftell(libfile);
	if(fread(buf,1,8,libfile)!=8)
	{
		addError("Error reading from file %s",mod->file);
		return FALSE;
	}
	buf[8]=0;
	/* complain if file header is wrong */
	if(strcmp(buf,"!<arch>\n"))
	{
		addError("Invalid library file format - bad file header: \"%s\"",buf);
		return FALSE;
	}
	/* read archive member header */
	if(fread(buf,1,60,libfile)!=60)
	{
		addError("Error reading from file %s",mod->file);
		return FALSE;
	}
	if((buf[58]!=0x60) || (buf[59]!='\n'))
	{
		addError("Invalid library file format for %s - bad member signature",mod->file);
		return FALSE;
	}
	buf[16]=0;
	/* check name of first linker member */
	if(strcmp(buf,"/			   ")) /* 15 spaces */
	{
		addError("Invalid library file format for %s - bad member name",mod->file);
		return FALSE;
	}
	buf[58]=0;

	/* strip trailing spaces from size */
	endptr=buf+57;
	while((endptr>(buf+48)) && isspace(*endptr))
	{
		*endptr=0;
		endptr--;
	}
	/* get size */
	errno=0;
	memberSize=strtoul(buf+48,(PPCHAR)&endptr,10);
	if(errno || (*endptr))
	{
		addError("Invalid library file format - bad member size\n");
		return FALSE;
	}
	if((memberSize<4) && memberSize)
	{
		addError("Invalid library file format - bad member size\n");
		return FALSE;
	}
	if(!memberSize)
	{
		numsyms=0;
	}
	else
	{
		if(fread(buf,1,4,libfile)!=4)
		{
			addError("Error reading from file\n");
			return FALSE;
		}
		numsyms=buf[3]+(buf[2]<<8)+(buf[1]<<16)+(buf[0]<<24);
	}
	modbuf=(PUCHAR)checkMalloc(numsyms*4);
	if(numsyms)
	{
		if(fread(modbuf,1,4*numsyms,libfile)!=4*numsyms)
		{
			addError("Error reading from file\n");
			return FALSE;
		}
		symlist=(PPSYMBOL)checkMalloc(sizeof(PSYMBOL)*numsyms);
	}
	for(i=0;i<numsyms;i++)
	{
		modpage=modbuf[3+i*4]+(modbuf[2+i*4]<<8)+(modbuf[1+i*4]<<16)+(modbuf[i*4]<<24);
		name=NULL;
		for(j=0;TRUE;j++)
		{
			if((x=getc(libfile))==EOF)
			{
				addError("Error reading from file\n");
				return FALSE;
			}
			if(!x) break;
			name=(char*)checkRealloc(name,j+2);
			name[j]=x;
			name[j+1]=0;
		}
		if(!name)
		{
			addError("NULL name for symbol %li\n",i);
			return FALSE;
		}
		symlist[i]=createSymbol(name,PUB_LIBSYM,mod,modpage,isDjgpp?DJGPPLibModLoad:MSCOFFLibModLoad);
	}

	checkFree(modbuf);
	if(ftell(libfile)!=(startPoint+68+memberSize))
	{
		addError("Invalid first linker member: Pos=%08lX, should be %08lX",ftell(libfile),startPoint+68+memberSize);
		return FALSE;
	}

	/* move to an even byte boundary in the file */
	if(ftell(libfile)&1)
	{
		fseek(libfile,1,SEEK_CUR);
	}

	startPoint=ftell(libfile);

	/* read archive member header */
	if(fread(buf,1,60,libfile)!=60)
	{
		addError("Error reading from file\n");
		return FALSE;
	}
	if((buf[58]!=0x60) || (buf[59]!='\n'))
	{
		addError("Invalid library file format - bad member signature\n");
		return FALSE;
	}
	buf[16]=0;
	/* check name of second linker member */
	if(!strcmp(buf,"/			   ")) /* 15 spaces */
	{
		/* OK, so we've found it, now skip over */
		buf[58]=0;

		/* strip trailing spaces from size */
		endptr=buf+57;
		while((endptr>(buf+48)) && isspace(*endptr))
		{
			*endptr=0;
			endptr--;
		}
		/* get size */
		errno=0;
		memberSize=strtoul(buf+48,(PPCHAR)&endptr,10);
		if(errno || (*endptr))
		{
			addError("Invalid library file format - bad member size\n");
			return FALSE;
		}
		if((memberSize<8) && memberSize)
		{
			addError("Invalid library file format - bad member size\n");
			return FALSE;
		}

		/* move over second linker member */
		fseek(libfile,startPoint+60+memberSize,SEEK_SET);
		/* move to an even byte boundary in the file */
		if(ftell(libfile)&1)
		{
			fseek(libfile,1,SEEK_CUR);
		}
	}
	else
	{
		fseek(libfile,startPoint,SEEK_SET);
	}
	startPoint=ftell(libfile);
	longnames=NULL;

	/* read archive member header */
	if(fread(buf,1,60,libfile)!=60)
	{
		addError("Error reading from file\n");
		return FALSE;
	}
	if((buf[58]!=0x60) || (buf[59]!='\n'))
	{
		addError("Invalid library file format - bad 3rd member signature\n");
		return FALSE;
	}
	buf[16]=0;
	/* check name of long names linker member */
	if(!strcmp(buf,"//			  ")) /* 14 spaces */
	{
		buf[58]=0;

		/* strip trailing spaces from size */
		endptr=buf+57;
		while((endptr>(buf+48)) && isspace(*endptr))
		{
			*endptr=0;
			endptr--;
		}
		/* get size */
		errno=0;
		memberSize=strtoul(buf+48,(PPCHAR)&endptr,10);
		if(errno || (*endptr))
		{
			addError("Invalid library file format - bad member size\n");
			return FALSE;
		}
		if(memberSize)
		{
			longnames=(PUCHAR)checkMalloc(memberSize);
			if(fread(longnames,1,memberSize,libfile)!=memberSize)
			{
				addError("Error reading from file\n");
				return FALSE;
			}
		}
	}
	else
	{
		/* if no long names member, move back to member header */
		fseek(libfile,startPoint,SEEK_SET);
	}

	mod->formatSpecificData=longnames;
	for(i=0;i<numsyms;++i)
	{
		addGlobalSymbol(symlist[i]);
	}

	checkFree(symlist);
	return TRUE;
}
Maze * Maze_construct(char * fileName)
{
  int numRow = 0;
  int numCol = 0;
  int row, col;
  int ch;
  FILE * fptr = fopen(fileName, "r");
  if (fptr == 0)
    {
      fprintf(stderr, "open %s fail\n", fileName);
      return NULL;
    }
  Maze_findSize(fptr, & numRow, & numCol);
  Maze * mzptr = malloc(sizeof(Maze));
  checkMalloc(mzptr, "mzptr");
  mzptr -> numRow = numRow;
  mzptr -> numCol = numCol;
  // create a two-dimensional array to store the cells 
  mzptr -> cells = malloc(numRow * sizeof(int *));
  checkMalloc(mzptr -> cells, "mzptr -> cells");
  for (row = 0; row < numRow; row ++)
    {
      mzptr -> cells[row] = malloc(numCol * sizeof(int));
      checkMalloc(mzptr -> cells[row], 
			 "mzptr -> cells[row]");
      // initialize the cells to invalid 
      for (col = 0; col < numCol; col ++)
	{
	  (mzptr -> cells)[row][col] = INVALIDSYMBOL;
	}
    }
  // move fptr to the beginning 
  fseek(fptr, 0, SEEK_SET);

  // read the file again and fill the two-dimensional array
  row = 0;
  while ((! feof(fptr)) && (ch != EOF) && (row < numRow))
    {
      // fill one row 
      col = 0;
      do 
	{
	  ch = fgetc(fptr);
	  if (ch != EOF) 
	    {
	      // notice that '\n' is also stored 
	      (mzptr -> cells)[row][col] = ch;
	      switch (ch)
		{
		case STARTSYMBOL:
		  mzptr -> startRow = row;
		  mzptr -> startCol = col;
		  mzptr -> curRow = row;
		  mzptr -> curCol = col;
		  break;
		case EXITSYMBOL:
		  mzptr -> exitRow = row;
		  mzptr -> exitCol = col;
		  break;
		}
	      col ++;
	    }
	} while ((ch != EOF) && (ch != '\n'));
      // checking '\n" to handle non-rectangular mazes
      row ++;
    }
  fclose(fptr);
  return mzptr;
}
Example #19
0
/*
 *Creates turtle structure
 */
void createTurtle()	{

	Turtle t = checkMalloc(malloc(sizeof(*t)));
	getTurtle(t);
	initTurtle();
}