string in c with pointers !
when i am creating a C program , in which i am using Strings with the help of pointers !
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char *ptr = "hello"; // line :: 1 printf("%s\n",*ptr); // line :: 2 return 0 ; } so , at line :: 1 , i am facing this problem :: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] at line :: 2 , i am facing this problem :: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat] |
Hi.
And the question is...? The second warning is actually an error, because you provide character `h' (*ptr == 'h' in your case) instead of a pointer to a memory location (that is instead of a string). |
Code:
int main (void) |
All times are GMT -5. The time now is 01:22 PM. |