Cannot determine why pointer variable will not address elements in a string in this program?
Posted
by
Smith Will Suffice
on Stack Overflow
See other posts from Stack Overflow
or by Smith Will Suffice
Published on 2013-11-11T03:47:08Z
Indexed on
2013/11/11
3:52 UTC
Read the original article
Hit count: 191
I am attempting to utilize a pointer variable to access elements of a string and there are issues with my code generating a compilation error:
#include <stdio.h>
#define MAX 29
char arrayI[250];
char *ptr;
int main(void)
{
ptr = arrayI;
puts("Enter string to arrayI: up to 29 chars:\n");
fgets(arrayI, MAX, stdin);
printf("\n Now printing array by pointer:\n");
printf("%s", *ptr);
ptr = arrayI[1]; //(I set the pointer to the second array char element)
printf("%c", *ptr); //Here is where I was wanting to use my pointer to
//point to individual array elements.
return 0;
}
My compiler crieth:
[Warning] assignment makes pointer from integer without a cast [enabled by default]
I do not see where my pointer was ever assigned to the integer data type? Could someone please explain why my attempt to implement a pointer variable is failing? Thanks all!
© Stack Overflow or respective owner