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. Why does a letter disappear when I'm writing the following (the problem is the underlined code.)

Why does a letter disappear when I'm writing the following (the problem is the underlined code.)

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 4 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.
  • H Offline
    H Offline
    hubblee
    wrote on last edited by
    #1

    char a, b;

    printf ("write two letters")
    scanf("%c %c", &a,&b);

    printf("%c %c",b, a );
    
    return 0;
    

    when I run the program and press x and y for example y disappears when I use printf

    J Mircea NeacsuM L 3 Replies Last reply
    0
    • H hubblee

      char a, b;

      printf ("write two letters")
      scanf("%c %c", &a,&b);

      printf("%c %c",b, a );
      
      return 0;
      

      when I run the program and press x and y for example y disappears when I use printf

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      Could you copy and paste the code you're running? What you've posted won't compile.

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      L 1 Reply Last reply
      0
      • H hubblee

        char a, b;

        printf ("write two letters")
        scanf("%c %c", &a,&b);

        printf("%c %c",b, a );
        
        return 0;
        

        when I run the program and press x and y for example y disappears when I use printf

        Mircea NeacsuM Offline
        Mircea NeacsuM Offline
        Mircea Neacsu
        wrote on last edited by
        #3

        Is that a space in the middle of your scanf format? If so, you need to type “x(space)y”.

        Mircea

        L 1 Reply Last reply
        0
        • H hubblee

          char a, b;

          printf ("write two letters")
          scanf("%c %c", &a,&b);

          printf("%c %c",b, a );
          
          return 0;
          

          when I run the program and press x and y for example y disappears when I use printf

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Apart from the missing semi-colon at the end of the first printf statement, the code works fine.

          1 Reply Last reply
          0
          • J jeron1

            Could you copy and paste the code you're running? What you've posted won't compile.

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Works fine after fixing the missing semi-colon.

            1 Reply Last reply
            0
            • Mircea NeacsuM Mircea Neacsu

              Is that a space in the middle of your scanf format? If so, you need to type “x(space)y”.

              Mircea

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              No, it works with or without the space.

              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