Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

declaring a pointer inside a for loop to point to the end of an array.

$
0
0
Ok so i'm making a program that takes in a message, then prints it out backwards using a pointer. Sounds simple enough and it seems to be printing out properly however i keep getting a window that pops up on my desktop:

Posted Image

Here is my code:

#include <stdio.h>

int main()
{
    char arr[] = {0};
    int len = 0;
    char ch;
    char *p;


    printf("Enter message:  ");
    ch = getchar();

    while (ch != '\n')
    {
        arr[len] = ch;
        ch = getchar();
        len++;
    }

    p = (arr+len);

    for (p; p >= arr; p--)
    {
        printf("%c", *p);
    }

    return 0;
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>