Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. // get input for name
  7. if (argc > 4)
  8. {
  9. printf("Too many arguments\n");
  10. }
  11. else if (argc == 1)
  12. {
  13. printf("At least 1 argument required\n");
  14. }
  15. else if (argc == 4)
  16. {
  17.  
  18. char* first = argv[1];
  19. char* last = argv[2];
  20. char* index_str = argv[3];
  21. int index = atoi(index_str);
  22.  
  23. int total = strlen(first) + strlen(last);
  24.  
  25. int j = 0;
  26. for (j; j <= index; j ++)
  27. {
  28. printf("The name is: %s %s\n", first, last);
  29. }
  30.  
  31. if (total < index)
  32. {
  33. printf("Error, index out of bound\n");
  34. }
  35. else if (strlen(first) > strlen(last))
  36. {
  37. printf("My first name is bigger than my last name\n");
  38. }
  39. else if (strlen(first) < strlen(last))
  40. {
  41. printf("My last name is bigger than my first name\n");
  42. }
  43. else
  44. {
  45. printf("My first and last name have the same number of characters\n");
  46. }
  47.  
  48. char fullName[12];
  49. /* strcpy(fullName, first); */
  50. strcpy(fullName, first);
  51. strcat(fullName, last);
  52. char char1 = fullName[index];
  53. int i = 0;
  54. for (i; i < total; i ++)
  55. {
  56. fullName[i] = tolower(fullName[i]);
  57. }
  58.  
  59. printf("fullName[%d]: %c\n", index, toupper(char1));
  60. printf("name in lower: %s\n", fullName);
  61.  
  62. }
  63. else
  64. {
  65. printf("Name is too long (2 words max)\n");
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement