Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include <ctype.h>
  6.  
  7. bool all_alpha(const char *str)
  8. {
  9. char c;
  10.  
  11. while ((c = *str++) != '\0')
  12. if (!isalpha(c))
  13. return false;
  14. return true;
  15. }
  16.  
  17. int main (int argc, char *argv[])
  18. {
  19. char *prenom = argv[1];
  20. char *nom = argv[2];
  21.  
  22. if(!all_alpha(prenom))
  23. printf("\"%s\" is not a valid firstname\n", prenom);
  24. else if(!all_alpha(nom))
  25. printf("\"%s\" is not a valid lastname\n", nom);
  26. else
  27. {
  28. char nomU[9] = {0};
  29. int i;
  30. for(i = 0; i < strlen(nom) && i < 7; i++)
  31. if(nom[i] >= 'A' && nom[i] <= 'Z')
  32. nomU[i] = (char)(nom[i] - 'A' + 'a');
  33. else
  34. nomU[i] = nom[i];
  35.  
  36. if(prenom[0] >= 'A' && prenom[0] <= 'Z')
  37. nomU[i] = (char)(prenom[0] - 'A' + 'a');
  38. else
  39. nomU[i] = prenom[0];
  40.  
  41. printf("%s\n", nomU);
  42. }
  43.  
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement