Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getchar and getche problem

Getchar and getche problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sachin ahuja
    wrote on last edited by
    #1

    Hi All I am using one console application and using getche and getchar function in this application. ch = getchar(); ch1 = getche(); I found that using getchar when I press enter I get value 10(LF) in ch. and when I press enter for getche() function i get value 13(CR) in ch1. Why am I not getting the same value in both function? When enter is pressed then two values are passed.that are 10(LF) and 13(CR). So value of ch1 must also be 10 in place of 13. Can anyone help me why I am getting different values in both functions. Thanks in advance BR Sachin Ahuja

    K 1 Reply Last reply
    0
    • S sachin ahuja

      Hi All I am using one console application and using getche and getchar function in this application. ch = getchar(); ch1 = getche(); I found that using getchar when I press enter I get value 10(LF) in ch. and when I press enter for getche() function i get value 13(CR) in ch1. Why am I not getting the same value in both function? When enter is pressed then two values are passed.that are 10(LF) and 13(CR). So value of ch1 must also be 10 in place of 13. Can anyone help me why I am getting different values in both functions. Thanks in advance BR Sachin Ahuja

      K Offline
      K Offline
      kasturi_haribabu
      wrote on last edited by
      #2

      Are you using both the function calls in a sequence? i mean one statement after the other? if Yes, Pressing "Enter" button does mean you are entering \r\n together into the stdin(keyboard) buffer.The first getchar() is returning the "\r". and the second getche() is returning the "\n" . can you test using getchar() once in your function and then, replace the getchar() with getche() and then verify result? regards, haribabu

      S 1 Reply Last reply
      0
      • K kasturi_haribabu

        Are you using both the function calls in a sequence? i mean one statement after the other? if Yes, Pressing "Enter" button does mean you are entering \r\n together into the stdin(keyboard) buffer.The first getchar() is returning the "\r". and the second getche() is returning the "\n" . can you test using getchar() once in your function and then, replace the getchar() with getche() and then verify result? regards, haribabu

        S Offline
        S Offline
        sachin ahuja
        wrote on last edited by
        #3

        Hi I have tried replacing getchar with getche in the function, but I am getting the same problem yet. Also I am not using getchar and getche in sequence. Rather I am using them in different functions. Please reply if you find some solution. Thanks Sachin Ahuja

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups