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. Define 'Enter' key in C

Define 'Enter' key in C

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • M Offline
    M Offline
    Mohamed Nehad
    wrote on last edited by
    #1

    How can i define the enter key to stop a working loop in my program ? for advance .. 2-programs here which enter key defined both with different ways ! ==============

    #include
    #include
    #include

    int main()
    {

    int x=1;
    r:
        printf("Allah  %d\\n", x);
        x++;
        while ( getch() != '\\r')
        {
            goto r;
        }
        return 0;
    

    }

    and the other one ..

    #include
    #include
    #include

    int main()
    {
    int nm = 0, ch = 0, wr = 1,i=0;
    char x;

    while ((x=getchar()) != '\\n')
    {
    	if (isdigit(x))
    	{
    		nm++;
    	}
    	else if (isalpha(x))
    	{
    		ch++;
    	}
    	else if (x == ' ')
    	{
    		wr++;
    	}
    	i++;
    }
    printf(" \\n");
    
    printf("Numbers entered = %d , Characters entered = %d , Words entered = %d", nm, ch, wr);
    printf(" \\n");
    system("pause");
    return 0;
    

    }

    The first one enter was defined as '\r' while the second was '\n' ! which is the right way ?!

    L 1 Reply Last reply
    0
    • M Mohamed Nehad

      How can i define the enter key to stop a working loop in my program ? for advance .. 2-programs here which enter key defined both with different ways ! ==============

      #include
      #include
      #include

      int main()
      {

      int x=1;
      r:
          printf("Allah  %d\\n", x);
          x++;
          while ( getch() != '\\r')
          {
              goto r;
          }
          return 0;
      

      }

      and the other one ..

      #include
      #include
      #include

      int main()
      {
      int nm = 0, ch = 0, wr = 1,i=0;
      char x;

      while ((x=getchar()) != '\\n')
      {
      	if (isdigit(x))
      	{
      		nm++;
      	}
      	else if (isalpha(x))
      	{
      		ch++;
      	}
      	else if (x == ' ')
      	{
      		wr++;
      	}
      	i++;
      }
      printf(" \\n");
      
      printf("Numbers entered = %d , Characters entered = %d , Words entered = %d", nm, ch, wr);
      printf(" \\n");
      system("pause");
      return 0;
      

      }

      The first one enter was defined as '\r' while the second was '\n' ! which is the right way ?!

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

      What happens when you try it?

      M 1 Reply Last reply
      0
      • L Lost User

        What happens when you try it?

        M Offline
        M Offline
        Mohamed Nehad
        wrote on last edited by
        #3

        Both programs debug well ! :/

        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