[ create a new paste ] login | about

Link: http://codepad.org/GX2Lcn63    [ raw code | output | fork ]

C, pasted on Oct 30:
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>

/* Algumas variáveis globais */
int opc;
char buff[256];
char sexo[5];
char nome[150];


	MYSQL conexao;
	
int main()
{
	

	mysql_init(&conexao);
	if(mysql_real_connect(&conexao, "localhost","root", 
	"root", "agenda",  0, NULL, 0))
	{
		printf("Conectado com sucesso!\n");
		cadastra();
		mysql_close(&conexao);
	}
	else
	{
		printf("Houve uma falha ao tentar conectar! \n");
		printf("Erro: %d %s\n",mysql_errno(&conexao), 
		mysql_error(&conexao));
	}
	return (0);
}

int cadastra()
{
	printf("\n\n\t\tMenu:\n");
	printf("\t\t--------------\n");
	printf("\t\t[1] Inserir\n"
	"\t\t[2] Buscar\n"
	"\t\t[3] Listar\n"
	"\t\t[4] Remover\n"
	"\t\t[0] Sair\n"
	"\t\t\t>> ");

	scanf("%d",&opc);

	switch(opc)
	{
		case 0:
			getchar();
		break;

		case 1:
			printf("Nome: ");
			scanf("%s",&nome);
			printf("Sexo: (M/F) ");
			scanf("%c",&sexo);
sprintf(buff, "INSERT INTO aprendendo(nome, sexo) values('%s','%c');", nome, sexo); 


		break;

		case 2:
			printf("Digite o nome: ");
		break;
	
		case 3:
			printf("\t\tListando cadastros:\n");
			printf("\t\t-----------------------\n");
		break;
		
		case 4:  
			printf("Digite o nome a ser removido: ");
		break;

		default:
			printf("Opcao invalida! \n");
			return EXIT_FAILURE;
		break;
		}
		
	return (0);
}


Output:
1
2
3
4
5
6
Line 24: error: mysql/mysql.h: No such file or directory
Line 12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'conexao'
In function 'main':
Line 18: error: 'conexao' undeclared (first use in this function)
Line 18: error: (Each undeclared identifier is reported only once
Line 18: error: for each function it appears in.)


Create a new paste based on this one


Comments: