Both programs debug well ! :/
M
Mohamed Nehad
@Mohamed Nehad
Posts
-
Define 'Enter' key in C -
How to break an infinite loopIf i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.
-
Define 'Enter' key in CHow 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
#includeint main()
{int x=1; r: printf("Allah %d\\n", x); x++; while ( getch() != '\\r') { goto r; } return 0;
}
and the other one ..
#include
#include
#includeint 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 ?!