Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main(int argc, char* argv[])
- {
- // get input for name
- if (argc > 4)
- {
- printf("Too many arguments\n");
- }
- else if (argc == 1)
- {
- printf("At least 1 argument required\n");
- }
- else if (argc == 4)
- {
- char* first = argv[1];
- char* last = argv[2];
- char* index_str = argv[3];
- int index = atoi(index_str);
- int total = strlen(first) + strlen(last);
- int j = 0;
- for (j; j <= index; j ++)
- {
- printf("The name is: %s %s\n", first, last);
- }
- if (total < index)
- {
- printf("Error, index out of bound\n");
- }
- else if (strlen(first) > strlen(last))
- {
- printf("My first name is bigger than my last name\n");
- }
- else if (strlen(first) < strlen(last))
- {
- printf("My last name is bigger than my first name\n");
- }
- else
- {
- printf("My first and last name have the same number of characters\n");
- }
- char fullName[12];
- /* strcpy(fullName, first); */
- strcpy(fullName, first);
- strcat(fullName, last);
- char char1 = fullName[index];
- int i = 0;
- for (i; i < total; i ++)
- {
- fullName[i] = tolower(fullName[i]);
- }
- printf("fullName[%d]: %c\n", index, toupper(char1));
- printf("name in lower: %s\n", fullName);
- }
- else
- {
- printf("Name is too long (2 words max)\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement