|
Hi, Better use fgets followed by sscanf. Ex: A sample program to use fgets main() { char input[10]; int num; printf(“Enter the
number : \t”); If (fgets(input, 10,
stdin) == NULL) { fprintf(stderr, “Enter
the proper input\n”); exit(1); } sscanf(input, “%d”,
&num); (or) num = atoi(input); printf(“The Entered
num is : %d”, num); } (If you want to
check the leading spaces, then we have to skip skip the spaces). main() { char input[10]; char *p; int num; printf(“Enter the
number : \t”); If (fgets(input, 10,
stdin) == NULL) { fprintf(stderr, “Enter
the proper input\n”); exit(1); } p = input; while (*p == ‘ ‘
|| *p == ‘\t’) p++; sscanf(p, “%d”,
&num); (or) num = atoi(p); printf(“The Entered
num is : %d”, num); } From: Thanks for replying.. To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
SPONSORED LINKS
YAHOO! GROUPS LINKS
__,_._,___ |
