Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
559 B
2
Indexable
Never
/*C program to print a string using pointer*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char str[20];
    char *pStr;
    int i;

    printf("Type a string: ");
    scanf("%s",str);

    gets(str);

    pStr=str;  //assigning pointer to string

    int length=0;       //getting length of the string
    for(i=0;str[i]!='\0';i++){
        length++;
    }

    int j;      //using pointer to print string in reverse
    for(j=0;j<length;j++){
        int num=length-j;
        printf("%c",*(pStr+num));
    }

    return 0;
}