To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Other Languages > C and C++

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Jan 17th, 2007, 07:33 PM   #1
Ph0b0s
Member
 
Join Date: Dec 03
Posts: 38
Ph0b0s is an unknown quantity at this point (<10)
Gives error on Visual Studio C++, but not on Dev-C++

I got this university project going... and then a weird error happen! Try it for your self. Put this code inside VSC++. You can run it with no problem... but press the 'i' key and then enter. I use 'i' to give me the info of the place i'm. In throws an error. Now, search:

//Comment from here
...
//To here

and comment the code and run it. The 'i' option works with no problem!




Now the nice stuff... if you run and compile the code, without commenting that piece of code, in Dev-C++, the program works perfectly. All the options work. Anyone knows what this can be about? MS Bug, or am i missing something?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char Mapa[11][11];
int LimiteLinhas, LimiteColunas, Pos[2];
int L, C, Vazio=1;

typedef struct elemento_lista {

  char * clausula;
  struct elemento_lista * proximo;

} elemento_lista_t;

typedef struct {
  elemento_lista_t * primeiro;
} lista_t;

lista_t * clausulas;

/*************************************************************/

lista_t* nova_lista() 
{

  lista_t *lista;
  lista = (lista_t*) malloc(sizeof(lista_t));
  lista->primeiro = NULL;
  return lista;
}

/*************************************************************/

void destroi_lista(lista_t *lista) {

  elemento_lista_t *elemento, *proximo;

  elemento = lista->primeiro;
  while(elemento != NULL) {
    proximo = elemento->proximo;
    free(elemento->clausula);
    free(elemento);
    elemento = proximo;
  }

  free(lista);
}

/*************************************************************/

void insere_clausula(lista_t *lista, char * clausula) 
{

  elemento_lista_t *novo_elemento, *elemento;

  novo_elemento = (elemento_lista_t*) malloc(sizeof(elemento_lista_t));
  novo_elemento->clausula = (char *) malloc(strlen(clausula)+1);
  strcpy(novo_elemento->clausula,clausula);
  novo_elemento->proximo = NULL;

  if(lista->primeiro == NULL) {
    lista->primeiro = novo_elemento;
    return;
  }

  elemento = lista->primeiro;
  lista->primeiro = novo_elemento;
  novo_elemento->proximo = elemento;

}

/*************************************************************/

void imprime_clausulas(lista_t *lista)
{

  elemento_lista_t *elemento = lista->primeiro;
  
  while (elemento != NULL) {
    printf("%s\n",elemento->clausula);
    elemento = elemento->proximo;
  }
}

void altera_clausula(lista_t *lista, char * clausula, char * NovoValor)
{

  elemento_lista_t *elemento = lista->primeiro;
  
  while (elemento != NULL) {
    if (!strcmp(elemento->clausula,clausula))
		{
		elemento->clausula = NovoValor;
		}
	elemento = elemento->proximo;
  }
}

void apaga_clausula(lista_t *lista, char * clausula) {

  elemento_lista_t *elemento, *proximo;

  elemento = lista->primeiro;
  while(elemento != NULL) {
    proximo = elemento->proximo;
	if (!(elemento->clausula[0],clausula))
	{
		elemento->clausula = "";
		//free(elemento);
	}
    elemento = proximo;
  }
  //free(lista);
}

int PreencheMapa()
{

	int ii, ii2;

	for (ii = 0; ii <= LimiteLinhas; ii++)
	{
		for (ii2 = 0; ii2 <= LimiteColunas; ii2++)
		{
			if (Mapa[ii][ii2] == 'M')
				{
					printf(".");
					Vazio = 0;
				}
			else
				if (Mapa[ii][ii2] == 'H')
					{
						printf("H");
						Vazio = 0;
					}
				else
					if (Pos[0] == ii & Pos[1] == ii2)
						{
							printf("@");
							Vazio = 0;
						}
					else
						{
							printf(" ");
						}

		}
		printf(" \n");
	}
}

int InicializaMapa()
{

	//Linha Superior
	Mapa[0][0] = 'M';
	Mapa[0][1] = 'M';
	Mapa[0][2] = 'M';
	Mapa[0][3] = 'M';
	Mapa[0][4] = 'M';
	Mapa[0][5] = 'M';
	Mapa[0][6] = 'M';
	Mapa[0][7] = 'M';
	Mapa[0][8] = 'M';
	Mapa[0][9] = 'M';

	//Linha Inferior
	Mapa[10][0] = 'M';
	Mapa[10][1] = 'M';
	Mapa[10][2] = 'M';
	Mapa[10][3] = 'M';
	Mapa[10][4] = 'M';
	Mapa[10][6] = 'M';
	Mapa[10][7] = 'M';
	Mapa[10][8] = 'M';
	Mapa[10][9] = 'M';

	//Linha Lateral esquerdo
	Mapa[2][0] = 'M';
	Mapa[3][0] = 'M';
	Mapa[4][0] = 'M';
	Mapa[5][0] = 'M';
	Mapa[6][0] = 'M';
	Mapa[7][0] = 'M';
	Mapa[8][0] = 'M';
	Mapa[9][0] = 'M';

	//Linha Lateral Direito
	Mapa[1][9] = 'M';
	Mapa[2][9] = 'M';
	Mapa[3][9] = 'M';
	Mapa[4][9] = 'M';
	Mapa[5][9] = 'M';
	Mapa[6][9] = 'M';
	Mapa[7][9] = 'M';
	Mapa[9][9] = 'M';
	Mapa[10][9] = 'M';

	//Desenha Hospital
	Mapa[2][2] = 'H';

}

int main(int argc, char ** argv)
{

	int i,j, area;
	char Movimento[1], Dados[100];

	//alocacao da memoria para a matriz
	int N=10;
	lista_t *** matriz = (lista_t ***) malloc(sizeof(lista_t**)*N);
	for(i=0;i<N;i++){
		matriz[i] = (lista_t **) malloc(sizeof(lista_t*)*N);
		for(j=0;j<N;j++){
			matriz[i][j] = nova_lista();
		}
	}

	//introdução de dados nas listas
	//***** HOSPITAL *****
	insere_clausula(matriz[2][2],"- Consulta de Podologia");
	insere_clausula(matriz[2][2],"- Internamento");
	insere_clausula(matriz[2][2],"- Consulta de Urgencia");
	insere_clausula(matriz[2][2],"Servicos:");
	insere_clausula(matriz[2][2],"** Hospital **");

	LimiteLinhas = 10;
	LimiteColunas = 10;

	Pos[0] = 1;
	Pos[1] = 0;

	InicializaMapa();
	PreencheMapa();

	while (1 != 0)
	{

		//*** Preenche o nosso ecran com as operacoes disponiveis ***
		printf("\n\nAs teclas de movimento sao:\n");
		printf("W - Cima\n");
		printf("S - Baixo\n");
		printf("A - Esquerda\n");
		printf("D - Direita\n");
		printf("i - Informacao Sobre Local Actual\n");
		printf("Z - Locais nas Imediacoes\n");
		printf("X - Inserir Nota\n");

		scanf("%s", Movimento);

		// ***** MOVIMENTOS *****

		if (Movimento[0] == 'd')
		{
			if (Pos[1] != LimiteColunas)
			{
				L = Pos[0];
				C = Pos[1]+1;
				if (Mapa[L][C] != 'M')
				{
					Pos[1] =C;
					system("cls"); //Limpa o ecran
					PreencheMapa(); //Funcao que vai preencher o nosso mapa.
				}
			}
		}
		if (Movimento[0] == 'a')
		{
			if (Pos[1] != (LimiteColunas - LimiteColunas))
			{
				L = Pos[0];
				C = Pos[1]-1;
				if (Mapa[L][C] != 'M')
				{
					Pos[1] = C;
					system("cls"); //Limpa o ecran
					PreencheMapa(); //Funcao que vai preencher o nosso mapa.
				}
			}
		}
		if (Movimento[0] == 's')
		{
			if (Pos[1] != LimiteLinhas)
			{
				L = Pos[0]+1;
				C = Pos[1];
				if (Mapa[L][C] != 'M')
				{
					Pos[0] = L;
					system("cls"); //Limpa o ecran
					PreencheMapa(); //Funcao que vai preencher o nosso mapa.
				}
			}
		}
		if (Movimento[0] == 'w')
		{
			if (Pos[1] != LimiteLinhas)
			{
				L = Pos[0]-1;
				C = Pos[1];
				if (Mapa[L][C] != 'M')
				{
					Pos[0] = L;
					system("cls"); //Limpa o ecran
					PreencheMapa(); //Funcao que vai preencher o nosso mapa.
				}
			}
		}
		if (Movimento[0] == 'i')
		{
			system("cls"); //Limpa o ecran
			PreencheMapa(); //Funcao que vai preencher o nosso mapa.
			imprime_clausulas(matriz[Pos[0]][Pos[1]]);
			//imprime_clausulas(Mapa[i][j]);
		}
		if (Movimento[0] == 'z')
		{
			system("cls"); //Limpa o ecran
			PreencheMapa(); //Funcao que vai preencher o nosso mapa.

			printf("Indique o raio da area\n");
			scanf("%i", &area);

			//Ex.: 1-1. Area = 1. Tem k apresentar: 0-0, 1-0, 2-0, 0-1, 1-1, 2-1, 0-2, 1-2, 2-2
			//Apresenta: 0-1

			for (i=(Pos[0]-area);i<=(Pos[0]+area);i++)
			{
				for (j=(Pos[1]-area);j<=(Pos[1]+area);j++)
				{
					imprime_clausulas(matriz[i][j]);
				}
			}


			//getch();

		}
		if (Movimento[0] == 'x')
		{
			system("cls"); //Limpa o ecran
			PreencheMapa(); //Funcao que vai preencher o nosso mapa.

			printf("Indique a nota a inserir -> ");
			gets(Dados);
  
			//scanf("%s", Dados);

			insere_clausula(matriz[Pos[0]][Pos[1]], Dados);
			//apaga_clausula(matriz[Pos[0]][Pos[1]], ">");
			imprime_clausulas(matriz[Pos[0]][Pos[1]]);
		}
	}

  ////listar conteudo das listas
  //for(i=0;i<N;i++){
	 // for(j=0;j<N;j++){
		//printf("lista: [%d|%d]\n",i+1,j+1);
		//imprime_clausulas(matriz[i][j]);
		//}
	 // }
    
  //libertar memoria
   for(i=0;i<N;i++){
	for(j=0;j<N;j++){
	
	destroi_lista(matriz[i][j]);
	  }
   free(matriz[i]);
  }
  
  free(matriz);
       
  return 0;
}
Ph0b0s is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > C and C++


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:16 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.