help me

Discussion in 'C' started by karun_happy, Nov 28, 2006.

  1. karun_happy

    karun_happy New Member

    Joined:
    Nov 17, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    hi,help me out i m new to C
    i have made one program and i am facing a bit of problem with that can anyone here help me.here is the source
    Code:
    
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i=0;
    char ch[25],c;
    printf("enter ur name n press 0 to exit");
    do{
    c=getch();
    ch[i]=c;
    i++;
    }while(c!='0');
    i=i-1;
    ch[i]='\0';
    }
    this is the program asking the user to enter his/her name and end the program by pressing '0'...name should be entered with one by one character for example: name is happy user should enter h first then a then p ans so on and then press 0 to end it...everything is running fine but i m getting it's output..when program is compiled it ask the yser to enter the name but when i tried to enter the name it doesnot enter anything but when i press 0 then it ends the progarm....so tell me how to get the output
    thaxs
    regards
    Karun
     
    Last edited by a moderator: Nov 29, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You are using the function getch which does not reflect the characters on the screen. use getche instead of getch and it should be fine.
     
  3. dhanulakshmi

    dhanulakshmi New Member

    Joined:
    Nov 29, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    without using getch try with getchar...surely it will work
     
  4. friendsforniraj

    friendsforniraj New Member

    Joined:
    Nov 24, 2006
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    studying
    ya dhanulakshmi is write
    actually your program is working correctly it do takes the name and store it in d array
    problem?
    well getch() is a funtion which waits for a character to be input but it doesnot displays it on outputscreeen
    whereas getchar takes the character and displays it in d screen
    thats it
    hope u understend the problem
     
  5. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    There are lot of other problems. See the modified code
    Code:
    #include<stdio.h>
    
    int main()
    {
     int i=0;
     char ch[25],c;
     printf("enter ur name n press 0 to exit");
      do{
       c=getchar();
      ch[i]=c;
      i++;
     }while(c!='0');
     i=i-1;
     ch[i]='\0';
     return 0;
    }
     
  6. karun_happy

    karun_happy New Member

    Joined:
    Nov 17, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    thank u to all ...actually i got the solution before but thank you all for ur help...hope to get more help more u
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice