The error is here:

while (*sPtr != '\0') {
    ++length;
    ++sPtr;
}

At this point the sPtr point at the end of the string so in the second loop it never decrement.

for (int i = length; i >= 0; --i) {
    printf("%c", *(sPtr+1));
}

A possible solution can be this:

for (int i = length; i >= 0; --i) {
    printf("%c", *(sPtr));
    --sPtr;
}
Answer from Zig Razor on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ program-to-reverse-a-string-using-pointers
Program to Reverse a String using Pointers - GeeksforGeeks
August 7, 2024 - #include <bits/stdc++.h> using namespace std; void reverseString(char* str) { int l, i; char *begin_ptr, *end_ptr, ch; // Get the length of the string l = strlen(str); // Set the begin_ptr // initially to start of string begin_ptr = str; // Setting end_ptr initially to // the end of the string end_ptr = str + l - 1; // Swap the char from start and end // index using begin_ptr and end_ptr for (i = 0; i < l / 2; i++) { // swap character ch = *end_ptr; *end_ptr = *begin_ptr; *begin_ptr = ch; // update pointers positions begin_ptr++; end_ptr--; } } int main() { // Define a string char str[100] = "GeeksforGeeks"; cout << "Original String: " << str << endl; // Reverse the string reverseString(str); cout << "Reverse of the string: " << str << endl; return 0; }
๐ŸŒ
Reddit
reddit.com โ€บ r/cprogramming โ€บ reversing a string with pointers
r/cprogramming on Reddit: Reversing a String With Pointers
October 1, 2024 -

So i just got to pointers in the K&R C programming book and one of the challenges is to rewrite the functions we worked on previously and implement pointers. i am trying to understand the topics as well as i can before moving forward in the book so if you guys could tell me the best practices and what i should have done in this snippet of code i would greatly appreciated. for reference i was thinking about how i see temp numbers like i used less and less in replacement of ( ; check ; increment ). sorry if this post seems amateur.

#include <stdio.h>
#include <string.h>

void reverse(char *s) {
    char temp[20];
    int len = strlen(s); 
    s += len - 1;
    int i = 0;
    while (len--) {
        temp[i++] = *s--;
    }
    temp[i] = '\0';        // Null-terminate the reversed string
    printf("%s\n", temp);  // Print the reversed string
    
}

int main(void) {
    char string[20] = "hello world";
    reverse(string);
    return 0;
}
#include <stdio.h>
#include <string.h>


void reverse(char *s) {
    char temp[20];
    int len = strlen(s); 
    s += len - 1;
    int i = 0;
    while (len--) {
        temp[i++] = *s--;
    }
    temp[i] = '\0';        // Null-terminate the reversed string
    printf("%s\n", temp);  // Print the reversed string
    
}


int main(void) {
    char string[20] = "hello world";
    reverse(string);
    return 0;
}
๐ŸŒ
Medium
medium.com โ€บ @togunchan โ€บ reversing-a-string-in-c-using-pointers-a-step-by-step-guide-236746346254
How to Reverse a String in C Using Pointers โ€” Step-by-Step Explanation
November 23, 2025 - A simple guide to reversing a C string using pointers โ€” find the end, swap characters, and apply efficient pointer arithmetic.
๐ŸŒ
w3resource
w3resource.com โ€บ c-programming-exercises โ€บ pointer โ€บ c-pointer-exercise-22.php
C : Print a string in reverse order using pointer
#include <stdio.h> int main() { // Declaration of variables char str1[50]; // Original string char revstr[50]; // Reversed string char *stptr = str1; // Pointer to the original string char *rvptr = revstr; // Pointer to the reversed string int i = -1; // Counter initialized with -1 // Displaying the purpose of the program printf("\n\n Pointer : Print a string in reverse order :\n"); printf("------------------------------------------------\n"); printf(" Input a string : "); scanf("%s", str1); // Taking input of a string // Loop to find the length of the string by moving the pointer to the end w
๐ŸŒ
Java Guides
javaguides.net โ€บ 2023 โ€บ 09 โ€บ c-program-to-reverse-string-using-pointers.html
C Program to Reverse a String Using Pointers
September 12, 2023 - 2. Set one pointer at the start and another at the end of the string. 3. Swap the characters at the pointers' positions and move the pointers towards each other. 4. Repeat until the pointers meet or cross each other.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ c-reverse-a-string-using-pointer-123325
Reverse a String Using Pointer
Now, we will declare two pointer variables: one to point to the first element of the string 'str', and the other to point to the first element of the reversed string 'rev'. ... We need to find the end of the string so that we can start traversing ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ reverse-string-in-c
Reverse String in C - GeeksforGeeks
#include <stdio.h> #include <string.h> void rev(char* s) { // Initialize l and r pointers int l = 0; int r = strlen(s) - 1; char t; // Swap characters till l and r meet while (l < r) { // Swap characters t = s[l]; s[l] = s[r]; s[r] = t; // Move pointers towards each other l++; r--; } } int main() { char s[100] = "abcde"; // Reversing s rev(s); printf("%s", s); return 0; } ... Apart from the simple method mentioned above, there are few more methods which we can use to reverse the string.
Published ย  December 5, 2024
๐ŸŒ
Let's Code
codeitaway.wordpress.com โ€บ 2011 โ€บ 11 โ€บ 13 โ€บ c-program-to-to-reverse-the-given-string-using-pointers
C Program to TO REVERSE THE GIVEN STRING using Pointers | Let's Code
November 13, 2011 - void strev(char *str1, char *str2); main() { char *str1, *str2; printf("\n\n\t PLZ ENTER A STRING...: "); gets(str1); strev(str1,str2); printf("\n\t YOUR THE REVERSED STRING IS...: "); puts(str2); getch(); } void strev(char *str1, char *str2) ...
๐ŸŒ
Scanftree
scanftree.com โ€บ programs โ€บ c โ€บ reverse-a-string-using-pointers
Reverse a string using pointers | Basic , medium ,expert programs example in c,java,c/++
C program to reverse a string using pointers. #include <stdio.h> #include <conio.h> void main() { char *s; int len,i; clrscr(); printf("\nENTER A STRING: "); gets(s); len=strlen(s); printf("\nTHE REVERSE OF THE STRING IS:"); for(i=len;i>=0;i--) printf("%c",*(s+i)); getch(); }
๐ŸŒ
Teachics
teachics.org โ€บ home โ€บ data structures using c examples โ€บ c program to reverse a string using pointers
C program to reverse a string using pointers | Data Structures Using C Examples | Teachics
May 12, 2024 - #include <stdio.h> #include <string.h> int main() { char str[100]; int len, i; char *begin, *end, ch; printf("Enter a string: "); gets(str); len = strlen(str); begin = str; end = str; for (i = 0; i < len - 1; i++) end++; for (i = 0; i < len / 2; i++) { ch = *end; *end = *begin; *begin = ch; begin++; end--; } printf("Reverse of the string is: %s", str); return 0; }
๐ŸŒ
W3Schools
w3schools.in โ€บ c-programming โ€บ examples โ€บ reverse-a-string-in-c
Reverse a String in C
In this chapter, you will know how to implement two different concepts and logic of reversing a string manually without using any specific predefined function. Reversing a string means the string that will be given by the user to your program in a specific sequence will get entirely reversed when the reverse of a string algorithm gets implemented in that particular input string.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ reverse-a-string-in-c-cplusplus
Reverse a string in C/C++
May 21, 2025 - In this example, we use two-pointer technique that result the string characters from right to left: ... #include <stdio.h> #include <string.h> // function to reverse a string in place void revString(char *str) { // Pointer intialization for left and right side characters int left = 0, right = strlen(str) - 1; // loop until left pointer crosses right pointer while (left < right) { char temp = str[left]; str[left] = str[right]; str[right] = temp; left++; right--; } } int main() { char str[] = "Tutorialspoint"; revString(str); printf("Reversed String: %s\n", str); return 0; }
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ reverse-string
How to Reverse a String in C? (8 Programs)
October 23, 2025 - Learn How to Reverse a String in C with 8 programs, including loops, recursion, and functions. Easy-to-follow examples for beginners and experts!
๐ŸŒ
C Program Examples
c-program-example.com โ€บ 2012 โ€บ 06 โ€บ write-a-c-program-to-reverse-a-string-using-pointers.html
Write a C program to reverse a string using pointers. - C Program Examples
June 11, 2012 - * * Happy Coding ***********************************************************/ #include<stdio.h> int main(){ int i=-1; char str[100]; char rev[100]; char *strptr = str; char *revptr = rev; printf("Enter the string:n"); scanf("%s",str); while(*strptr) { strptr++; i++; } while(i >=0) { strptr--; *strptr = *revptr; revptr++; --i; } printf("nn Reversed string is:%s",rev); return 0; }
๐ŸŒ
Medium
willfindu.medium.com โ€บ how-to-reverse-a-string-in-c-using-pointers-9cdfa3331474
How to reverse a string in C using Pointers | by Saurabh Dwivedy | Medium
March 8, 2024 - #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char str[] = "Abbas"; for(int x = strlen(str) - 1; x >= 0; x--) { printf("%c ", str[x]); } printf("\n"); int len = strlen(str); char* reversed = malloc(len + 1); if (reversed == NULL) { printf("Error allocating memory for pointer\n"); return -1; } // core logic for reversal for(int i = len - 1; i >= 0; i--) { reversed[len - i - 1] = str[i]; printf("str[%d] = %c, reversed[%d] = %c ", i, str[i], (len - i - 1), reversed[len - i - 1]); printf("\n"); } reversed[len] = '\0'; printf("The reversed string is: %s\n", reversed); free(reversed); return 0; }
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ reverse a string in c in 10 different ways (+code examples)
Reverse A String In C In 10 Different Ways (+Code Examples)
September 13, 2024 - We define a function with the name/ identifer reverseString() that accepts a pointer to a character array pointer as a parameter and reverses the string being pointed to. Inside this function: First, we initialize two pointers, start and end, ...
๐ŸŒ
DEV Community
dev.to โ€บ vadims4 โ€บ reversing-a-string-using-pointers-references-4fgn
Reversing A String Using Pointers(References) - DEV Community
October 27, 2019 - At this point, I cleared my IDE and starting going at this problem using pointers and modifying the origin array without creating a new one and not having to use helper methods such as .reverse(). I was able to use indexing and having pointers set to the first and last letters and then incrementing towards the middle of the array and swapping the letters. var reverseString = function(string) { let left = 0; let right = string.length - 1; while (left < right) { let temp = string[left]; string[left++] = string[right]; string[right--] = temp; } }; reverseString(["h", "e", "l", "l", "0"]) input = ["h", "e", "l", "l", "o"] output = ["o", "l", "l", "e", "h"]