reverse_string.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. **
  3. ** Copyright @ 2020 Joshua Branson <jbranso@member.fsf.org>
  4. **
  5. ** This program is free software; you can redistribute it and/or modify it
  6. ** under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation; either version 3 of the License, or (at
  8. ** your option) any later version.
  9. **
  10. ** It is distributed in the hope that it will be useful, but
  11. ** WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. void reverse (char * to, char * from)
  21. {
  22. char * from_start = from;
  23. int j, i, length = 0;
  24. for (; *(from + i) != '\0'; i++)
  25. ;
  26. length = --i;
  27. for (j = 0; (*(to + j) = *(from + i)) && i > 0; i--, j++)
  28. ;
  29. }
  30. int main ()
  31. {
  32. char * str = (char *) malloc (sizeof("hello"));
  33. reverse (str, "hello");
  34. printf ("%s\n", str);
  35. return 0;
  36. }