Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h> /// We include the string lib to use the function strlen()
- int main(int argc, char *argv[])
- {
- int loop = 0, i = 0, len = 0;
- char enter[50] = "";
- do /// With the do while loop the program will execute at least once because loop is equal to 0
- {
- printf("Enter something: ");
- scanf("%s", enter); /// We ask the user to enter something
- len = strlen(enter); /// len takes the value of the string enter
- for(i=0;i<len;i++) /// With this for loop we check if the characters are authorized refering to ASCII
- {
- if(enter[i] > 47 && enter[i] < 58) /// If it is a number the program stop
- {
- printf("Characters authorized %d\n", i);
- }
- else if(enter[i] > 64 && enter[i] < 91) /// If it is a small letter the program stop
- {
- printf("Characters authorized %d\n", i);
- }
- else if(enter[i] > 96 && enter[i] < 123)
- {
- printf("Characters authorized %d\n", i); /// If it is a capital letter the program stop
- }
- else
- {
- printf("Unauthorized character. \n"); /// If it is another character, loop is now equal to 1 and the loop repeat
- loop = 1;
- }
- }
- printf("\n\n", len);
- }while(loop);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement