Cannot determine why pointer variable will not address elements in a string in this program?
- by Smith Will Suffice
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!