USING STRING IN STRUCTURE

#include<stdio.h>

int main()

{

struct book

{

  char name;

  float price;

  int pages;

};

  struct book b1;

  b1.name=”vikas”

  printf(“%s”, b1.name);

  return 0;

}

// this will give error

 

Error assignment to expression with array type

For solution use strcpy function

 

#include<stdio.h>

int main()

{

struct book

{

  char name;

  float price;

  int pages;

};

  struct book b1;

  strcpy(b1.name, “vikas”);

  printf(“%”, b1.name); 

  return 0;

}

Output:vikas