Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- #include <ctype.h>
- bool all_alpha(const char *str)
- {
- char c;
- while ((c = *str++) != '\0')
- if (!isalpha(c))
- return false;
- return true;
- }
- int main (int argc, char *argv[])
- {
- char *prenom = argv[1];
- char *nom = argv[2];
- if(!all_alpha(prenom))
- printf("\"%s\" is not a valid firstname\n", prenom);
- else if(!all_alpha(nom))
- printf("\"%s\" is not a valid lastname\n", nom);
- else
- {
- char nomU[9] = {0};
- int i;
- for(i = 0; i < strlen(nom) && i < 7; i++)
- if(nom[i] >= 'A' && nom[i] <= 'Z')
- nomU[i] = (char)(nom[i] - 'A' + 'a');
- else
- nomU[i] = nom[i];
- if(prenom[0] >= 'A' && prenom[0] <= 'Z')
- nomU[i] = (char)(prenom[0] - 'A' + 'a');
- else
- nomU[i] = prenom[0];
- printf("%s\n", nomU);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement