edited by
2,448 views
0 votes
0 votes
#include <stdio.h>
#include<stdlib.h>
int main() {
    //code
    char *ptr,s[]="debasree";
    ptr=s[0];
    printf("%s\n",*ptr);
    return 0;
}

 

I get this warning in geeks for geeks compiler

Warnings:

prog.c: In function 'main':
prog.c:7:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   ptr=s[0];
 

prog.c:13:8: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
 printf("%s\n",*ptr);
     ^

and also get 

Runtime Errors:

Segmentation Fault (SIGSEGV)

can anyone pls explain what is the warning saying? i googled a lot but could not grasp it… pls pls pls pls explain...

edited by

1 Answer

Best answer
1 votes
1 votes

s[0] is a single character, you just have to do ptr=s or if you wanna go crazy maybe &(s[0]). Also, the main problem is 

printf("%s\n",*ptr);

It should be 

printf("%s\n",ptr);

Google out how to print strings using printf and go through more examples of pointers to clear your basics.

Also, see the line number in error its 7, see what's line 7. That's how you start debugging.

selected by

Related questions

1 votes
1 votes
1 answer
2
Na462 asked Jan 8, 2019
1,402 views
#include <stdio.h>main (){unsigned x = -10;int X = 20;if (X x) printf ("Hello");else{ printf ("%d",x); printf ("Jello"); }}