Jump to content

some errors in small program

- - - - -

  • Please log in to reply
2 replies to this topic

#1
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
I wrote this program


#include<stdio.h>

int main ()

{

int a;

char * c,d;

 c="Onus";

 d="animation";

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

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

}

but upon compiling I got following warning

temp.c: In function ‘main’:

temp.c:7: warning: assignment makes integer from pointer without a cast

temp.c:9: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’

and when I executed it executed with following errors


./a.out 


Onus

Segmentation fault

Can some one point me as what is wrong in above and why am I getting warning?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Why are you storing an array of chars into a pointer? You would initialize each string as a char array:
#include<stdio.h>
int main () {
    int a;
    char c[] = "Onus";
    char d[] = "animation";
    printf("\n%s",c);
    printf("\n%s",d);
}

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
onus

onus

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
Ok.Was just trying a new way.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users