Here is a simple C programs in structure but i dont quite get what am i doing wrong as the output is not what i desired ,
P1
#include<stdio.h>
struct book
{
char name[10];
char author[10];
int refno;
};
//passing whole structure variable
void display(struct book b)
{
printf("%s %s %d",b.name,b.author,b.refno);
}
int main()
{
struct book b1={"LET US C","YPK",25};
display(b1);
}
Here this one works completely fine with output:
LET US C YPK 25
--------------------------------
Process exited after 0.3952 seconds with return value 0
Press any key to continue . . .
BUT if i try
struct{
// element -1;
//element -2;
//element-3;
}b1;
/*then*/
int main()
{
b1={"LET US C","YPK",25};
display(b1);
It shows error messages:-
1:[Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11
2:[Error] no match for 'operator=' (operand types are 'book' and '<brace-enclosed initializer list>')
3:[Note] candidate is:
4:[Note] book& book::operator=(const book&)
5:[Note] no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const book&'
The same messsages are shown if i try :
struct book
{
//elements declarations as p1
}b[10];
int main()
{
b[1]={"LET US C","YPK",25};
display(b[1]);
}
OR WITH
struct book
{
//elements declarations as p1
};
int main()
{
struct book b[10];
b[1]={"LET US C","YPK",25};
display(b[1]);
}
So whats the problem?
and actually my main objective was to define array of structure, as in second last and last method but it does not seem to work so please help>