1typedef struct
2{
3 //add different parts of the struct here
4 string username;
5 string password;
6}
7user; // name of struct - you can name this whatever
8
9user example; //variable of type user
10
11example.username = "Comfortable Caterpillar"; // username part of example variable
12example.password = "password" // password part of example variable
13
14if (user.username == "Comfortable Caterpillar")
15{
16 printf("upvote this if it helped!");
17}
1#include <stdio.h>
2#include <string.h>
3
4typedef struct Books {
5 char title[50];
6 char author[50];
7 char subject[100];
8 int book_id;
9} Book;
10
11int main( ) {
12
13 Book book;
14
15 strcpy( book.title, "C Programming");
16 strcpy( book.author, "Nuha Ali");
17 strcpy( book.subject, "C Programming Tutorial");
18 book.book_id = 6495407;
19
20 printf( "Book title : %s\n", book.title);
21 printf( "Book author : %s\n", book.author);
22 printf( "Book subject : %s\n", book.subject);
23 printf( "Book book_id : %d\n", book.book_id);
24
25 return 0;
26}
1// Typedefs can also simplify definitions or declarations for structure pointer types. Consider this:
2
3struct Node {
4 int data;
5 struct Node *nextptr;
6};
7// Using typedef, the above code can be rewritten like this:
8
9typedef struct Node Node;
10
11struct Node {
12 int data;
13 Node *nextptr;
14};