typedef struct {
char cognome[30];
char nome[20];
int voto;
}alunno;
#include <stdio.h>
#include <stdlib.h>
struct book{ //this is like making a datatype of type book
//these are the fields
char name[50];
char author[50];
char ISBN[11];
};
int main(){
struct book book1; //making an instance of book called book1
/*
normally to store integers in a struct we can do something like
book1.number_of_pages = 22; which is correct
however with character arrays we need to use the strcpy
function
*/
strcpy(book1.name, "james and the giant tatti");
strcpy(book1.author, "Krishan Grewal");
strcpy(book1.ISBN, "12345678987");
printf("book name: %s
", book1.name);
printf("book author: %s
", book1.author);
printf("book ISBN: %s
", book1.ISBN);
return 0;
}
struct num{
int a ;
int b;
};
int main()
{
struct num n;
//accessing the elements inside struct
n.a=10;
n.b=20;
}
//option 1
typedef struct STRING{
char *str;
int length;
} STRING;
STRING var_name;
//option 2
struct STRING{
char *str;
int length;
};
struct STRING var_name;
struct structureName {
dataType member1;
dataType member2;
...
};
struct book{
int pages;
char author[30];
float price;
}b;
struct Person {
// code
};
int main() {
struct Person person1, person2, p[20];
return 0;
}