Jump to content

C language: Compilation execution error, when i am entering "char instead of integer"

- - - - -

  • Please log in to reply
4 replies to this topic

#1
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
#include<stdio.h>

void main()

{

int i,j,k;

printf(" enter numbers for i: ");

scanf("%d",&i);


printf(" enter numbers for j: ");

scanf("%d",&j);


printf(" enter numbers for k: ");

scanf("%d",&k);


if (i>j&&i>k)

{

printf("i is big ");

}


else if  (j>i&&j>k)

{

printf("j is big ");

}


else if  (k>i&&k>j)

{

printf("k is big ");

}


else


printf("enter proper value");

}



---------- Post added at 03:39 PM ---------- Previous post was at 03:31 PM ----------

when i am compiling then the Output is:


enter numbers for i: a
enter numbers for j: enter numbers for k: i is big


---------- Post added at 03:41 PM ---------- Previous post was at 03:39 PM ----------

Why it is not waiting to take the value for j and k variables?

#2
alex1

alex1

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Why I think it's reading the numbers- just try to change the line... using '\n' it will be more readable

#3
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts

Quote

alex1

Have a look at the output it already displayed the answer as soon as i entered the character "a"

#4
AKMafia001

AKMafia001

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
Well! You told the compiler that my variables are of type int and the format of the values to be stored is of type int (%d). While entering char type data without conversion confuses the compiler.


int i, j, k;             // int type variables


printf(" enter numbers for i: ");

scanf("%d",&i);     // format specifier -> %d


printf(" enter numbers for j: ");

scanf("%d",&j);     // format specifier -> %d


printf(" enter numbers for k: ");

scanf("%d",&k);    // format specifier -> %d


I think i'm able to write a code for printing "Hello, World!". Proud of that!

#5
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Do you need to filter out chars or the user should just input numbers?
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users