Advertisement
tankmonx

Stop sleeping late, and start asking for help.

Nov 28th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. int needInput = 1, test=0;
  7.  
  8. char telNum[11];
  9. while (needInput == 1) {
  10. printf("Give me a phone number ");
  11. scanf("%10s", telNum);
  12.  
  13. for (size_t i = 0; i < strlen(telNum); i++)
  14. {
  15. if (telNum[i] >= '0' && telNum[i] <= '9') {
  16. printf("This is a number %c\n", telNum[i]);
  17. test ++;
  18. }
  19. else
  20. {
  21. printf("This is not a number %c\n", telNum[i]);
  22. }
  23.  
  24. }
  25. // (String Length Function: validate entry of 10 characters)
  26.  
  27.  
  28. if (test == 10) {
  29.  
  30. printf("Yep, thats a phone number \n");
  31. needInput = 0;
  32. }
  33. else {
  34. printf("Enter a 10-digit phone number: \n");
  35. test = 0;
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement