Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

how to reverse a string in c


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

int main()
{
    char str[2][100];
    printf("Type Text: ");

    scanf("%[^
]%*c", str[0]);
    int length = strlen(str[0]);
    int i, j;
    for (i = 0, j = length - 1; i < length; i++, j--)
    {
        str[1][i] = str[0][j];
    }
    printf("Original Word: %s
", str[0]);
    printf("Reverse word: %s
", str[1]);
    return 0;
}
 
PREVIOUS NEXT
Tagged: #reverse #string
ADD COMMENT
Topic
Name
8+3 =