NO

Author Topic: warning #2055: Excess characters in 'char' character literal ignored.  (Read 4179 times)

sannemander

  • Guest
Hello,

I got a question about this code, I don't understand why I get this warning.

Code: [Select]
#include<stdio.h>

int main(void)
{

float CurrentVal, NextNum;
char ch;


printf("Enter an expression: ");
scanf("%f", &CurrentVal);

while ((ch = getchar()) != '/n') {

switch(ch){

case '+':
scanf("%f", &NextNum);
CurrentVal += NextNum;
break;

case '-':
scanf("%f", &NextNum);
CurrentVal -= NextNum;
break;

case '*':
scanf("%f", &NextNum);
CurrentVal *= NextNum;
break;

case '/':
scanf("%f", &NextNum);
if (NextNum == 0){
printf("False, cannot divide by 0!/n");
return 1;}
else{
CurrentVal /= NextNum;
break;}

}

}

printf("Value of expression is %.2f/n", CurrentVal);

return 0;

}

now I get warning 2055: Excess characters in 'char' literal ignored.

CommonTater

  • Guest
Re: warning #2055: Excess characters in 'char' character literal ignored.
« Reply #1 on: April 24, 2012, 11:41:51 AM »
   '/n'  Should be... '\n'
 
 

« Last Edit: April 24, 2012, 11:44:28 AM by CommonTater »

sannemander

  • Guest
Re: warning #2055: Excess characters in 'char' character literal ignored.
« Reply #2 on: April 24, 2012, 11:54:37 AM »
Ah you´re right, I have found the solution to the problem already, now it´s:

Code: [Select]
#include<stdio.h>

int main(void)
{

float CurrentVal, NextNum;
char ch;


printf("Enter an expression: ");
scanf("%f", &CurrentVal);

do{scanf("%c", &ch);


switch(ch){

case '+':
scanf("%f", &NextNum);
CurrentVal += NextNum;
break;

case '-':
scanf("%f", &NextNum);
CurrentVal -= NextNum;
break;

case '*':
scanf("%f", &NextNum);
CurrentVal *= NextNum;
break;

case '/':
scanf("%f", &NextNum);
if (NextNum == 0){
printf("False, cannot divide by 0!/n");
return 1;}
else{
CurrentVal /= NextNum;
break;}

}

}while (ch != '\n');

printf("Value of expression is %.2f\n", CurrentVal);

return 0;

}


Works perfectly now!