Thread: What is the error??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User linuxlover's Avatar
    Join Date
    Nov 2010
    Location
    INDIA
    Posts
    52

    Unhappy What is the error??

    My problem is this.

    First I need to read a single integer type digit from the keyboard.

    Then I need to print that digit in character form.ie. if I entered 1 ,I need to get the character constant '1' as output.

    In the second case I need to read a character from keyboard .If it is any one of characters 0 - 1, it will printed in the decimal form.
    ie. if I enter character 1 , I need to get decimal value 1 as output.

    The program is simple but I dont get correct output.
    ie. I got output of first case .
    In the second case I 'm not getting any output.ie program doesn't stops.
    I checked whether there is an infinite loop by putting a printf() statement .
    But there is no infinite loop.
    Then what is my problem.

    Code is this:
    Code:
    #include<stdio.h>
    
    main()
    {       int digit , n = 0;
            char ch;
            printf("ENTER DIGIT:");
            scanf("%d",&digit);
    
             for( ch = 48;n < digit;++n , ch++ );
             printf("ENTERED DIGIT IS  %c \n",ch);
    
             printf("NOW ENTER A CHARACTER, IF IT IS A DIGIT THAT DIGIT IS PRINTED IN DECIMAL FORM:");
             scanf(" %c ",&ch);
    
             for( digit = 0  ; digit < ch - 48 ; digit++ );         
             printf("ENTERED CHARACTER  IS  %d \n",digit);
    
    }



    OS Linux
    compiler g++
    Last edited by linuxlover; 12-01-2010 at 01:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

Tags for this Thread