Advertisement
SamGauths

Limited entry in C

Nov 12th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>  /// We include the string lib to use the function strlen()
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.      int loop = 0, i = 0, len = 0;
  8.      char enter[50] = "";
  9.  
  10.      do /// With the do while loop the program will execute at least once because loop is equal to 0
  11.      {
  12.         printf("Enter something: ");
  13.         scanf("%s", enter);  /// We ask the user to enter something
  14.  
  15.         len = strlen(enter);  /// len takes the value of the string enter
  16.  
  17.         for(i=0;i<len;i++)  /// With this for loop we check if the characters are authorized refering to ASCII
  18.         {
  19.          if(enter[i] > 47 && enter[i] < 58) /// If it is a number the program stop
  20.          {
  21.               printf("Characters authorized %d\n", i);
  22.          }
  23.          else if(enter[i] > 64 && enter[i] < 91)  /// If it is a small letter the program stop
  24.          {
  25.               printf("Characters authorized %d\n", i);
  26.          }
  27.          else if(enter[i] > 96 && enter[i] < 123)
  28.          {
  29.               printf("Characters authorized %d\n", i); /// If it is a capital letter the program stop
  30.          }
  31.          else
  32.          {
  33.              printf("Unauthorized character. \n"); /// If it is another character, loop is now equal to 1 and the loop repeat
  34.              loop = 1;
  35.          }
  36.         }
  37.         printf("\n\n", len);
  38.      }while(loop);
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement