Advertisement
dtung

print and swap strings

Aug 18th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. void swap(char *a, char *b) {
  4.     char temp[15];
  5.     strcpy(temp, a);
  6.     strcpy(a, b);
  7.     strcpy(b, temp);
  8. }
  9.  
  10. void print(int n, char p[][15]) {
  11.     for (int i = 0; i < n; i++)
  12.         printf("%s ", p[i]);
  13.     printf("\n");
  14. }
  15.  
  16. int main() {
  17.     char test[4][15] = {"this", "is", "a", "test"};
  18.  
  19.     print(4, test);
  20.     swap(test[2], test[3]);
  21.     print(4, test);
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement