Advertisement
Guest User

3

a guest
Mar 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 3
  3. void FindLastName(char* names[], char* last[], int len);
  4. void Print(char* names[], int len);
  5. void main() {
  6. char *names[SIZE] = { "David Bowie", "Madonna", "Bob Marley" };
  7. char *last[SIZE];
  8. FindLastName(names, last, SIZE);
  9. printf("The full names are:\n");
  10. Print(names, SIZE);
  11. printf("The last names are:\n");
  12. Print(last, SIZE);
  13. }
  14. void FindLastName(char* names[], char* last[], int len) {
  15. for (int j = 0, i = 0; i < len; j = 0, i++) {
  16. while (names[i][j] != ' '&&names[i][j] != '\0') j++;
  17. if (names[i][j] == ' ') j++;
  18. last[i] = &names[i][j];
  19. }
  20. }
  21. void Print(char* names[], int len) {
  22. for (int i = 0; i < len; i++) puts(names[i]);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement