Advertisement
cd62131

String Limitation

Feb 5th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdbool.h>
  6. int main(void) {
  7.   const char *string[] = {"abcdefg", "abc,defg", "12abcdefghi", "ABCDE"};
  8.   for (int i = 0; i < sizeof(string) / sizeof(char *); i++) {
  9.     int len = strlen(string[i]);
  10.     printf("String: %s, length: %d", string[i], len);
  11.     if (len < 5 || len > 10) {
  12.       puts("");
  13.       continue;
  14.     }
  15.     bool except = false;
  16.     for (int j = 0; string[i][j]; j++)
  17.       if (!isalnum(string[i][j])) except = true;
  18.     if (except) {
  19.       puts("");
  20.       continue;
  21.     }
  22.     puts(", week");
  23.   }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement