Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int mystrlen(char *);
  4. void revstring(char *, int *);
  5. int main(void)
  6. {
  7.     char strinp[40];
  8.     int charcount;
  9.    
  10.     printf("Enter a string: ");
  11.     scanf("%[^\n]s", strinp);
  12.  
  13.     charcount = mystrlen(strinp);
  14.    
  15.     revstring(strinp, &charcount);
  16. }
  17.  
  18. int mystrlen(char strinp [])
  19. {
  20.     int count = 0;
  21.     char *ptr;
  22.     ptr = strinp;
  23.     while (strinp[count] != '\0') {
  24.         count++;
  25.     }
  26.     return count;
  27. }
  28.  
  29. void revstring(char strinp[], int *charcount)
  30. {
  31.     char *ptr;
  32.     ptr = strinp;
  33.     while (*charcount != -1) {
  34.         printf("%c", *(ptr + *charcount));
  35.         *charcount--;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement