Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
lex rocha

Problema com escape caracter

Recommended Posts

lex rocha

Qual o problema?

Desculpem, é que estou no primeiro periodo.

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

int main()
{
float vet1[5],vet3[5],res[5];
char vet2[5];
int i;

printf("\t\tPrograma Calculadora Vetor\n\n");
printf("\t\tOperadores\n\nDivisao (\)\nMultiplicacao (*)\nSubtracao	(-)\nAdicao (+)\n");
for (i=0;i<5;i++)
{
	printf("Digite o 1o Numero: ");
	scanf("%f",&vet1[i]);
	printf("Digite o Operador: ");
	scanf("%s",vet2[i]);
	printf("Digite o 2o Numero: ");
	scanf("%f",&vet3[i]);
	switch(vet2[i])
	{
		case '\': res[i]=vet1[i] \ vet3[i];break;
		case '*': res[i]=vet1[i] * vet3[i];break;
		case '-': res[i]=vet1[i] - vet3[i];break;
		case '+': res[i]=vet1[i] + vet3[i];break;
		default : printf("Operador Incorreto");
	}
}
printf("\t\tResultados\n\n");
for (i=0;i<5;i++)
{
	printf("A Resultado do %do  Calculo e: %.2f\n",i+1,res[i]);
}
return 0;
}

EDIT: Titulo modificado

Share this post


Link to post
Share on other sites
lex rocha

Achei a Resposta, pocha em vez de por '/' estava pondo a barra invertida '\'. 😲 :wallbash:

Share this post


Link to post
Share on other sites
HappyHippyHippo

case '\': res[i]=vet1[i] \ vet3[i];break;

o caracter \ é especial (escape caracter) ... para escrever esse caracter necessitas de fazer deste modo:

case '\\': res[i]=vet1[i] \ vet3[i];break;


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.