Structure Part I: The Basics
Today we are going to go through Structures from defining structures to using structures.Structures are just a collection of different types under one roof (you can even put one type only!). So that means they give you flexibility of grouping different data types (like int, char, or even char[]) under one name.So let us start with obviously defining a Structure. In `C` we declare a structure as simply as this:-struct dob {
int day;
int month;
int year;};1: In the above code segment struct is a keyword which defines structure.
2: Followed by struct keyword (dob) is the name of our structure.
3: Elements of struct are defined inside braces '{}' as we did (int day; etc).
4: After ending brace we place a terminator ';' to end the declaration.So now you know how to define a structure but how to create its instances now?To create a variable of our structure we just need to do this:struct dob date;This now declares date as a structure variable of type dob.1: Here 'struct dob' is our above declared structure.
2: date is a variable of type dob.So ok we have a structure and a variable of that type but how can i access its parts?well we can access it and assign it so simply like this:-date.day = 19;date.month = 10;date.year = 1990;Note here we use the dot (.) operator to access the fields (parts) of our structure.ok everything looks nice so for but how in the world can i read data into this structure variable? Again no worries its again simple:-scanf("%d", &date.day);scanf("%d", &date.month);that was pretty easy but I was wondering how can i print its data?Just do it like this:-printf("Day: %d", date.day);printf("Month: %d",date.month);printf("Year: %d", date.year);Again remember we use dot (.) operator to access members of a structure.So we now know how to define and declare a structure, how to access its members, how to read data in it, and how to print data of a structure. Oh that was a tough job..!Now let us put it together in a single C Program./***********************************************/
#include <stdio.h>
struct dob {
int day;
int month;
int year;
};
int main(void) {
struct dob date;
date.day = 19;
date.month = 10;
date.year = 1990;
printf("Day is : %d, Month is: %d, and Year is %d\n",
date.day,date.month, date.year);
printf("Enter Day, Month, and Year separated by spaces: ");
scanf("%d %d %d", &date.day,&date.month,&date.year);
printf("Your entered Date is: %d/%d/%d",
date.day,date.month,date.year);
return 0;
}
Output:Day is : 19, Month is: 10, and Year is 1990
Enter Day, Month, and Year separated by spaces: 1 1 2014
Your entered Date is: 1/1/2014 More info
- Hacking Wifi Kali Linux
- Curso Hacking Etico
- Herramientas Hacking Etico
Archivo del blog
-
▼
2020
(565)
-
▼
mayo
(77)
- TODO PARA EL HOGAR & JARDÍN + Nataly
- Proveedores para el Hogar & Jardín...
- Descubre las principales claves para recuperar la ...
- +ARQUITECTURA, CONSTRUCCIÓN, PAISAJISMO & MARKETIN...
- Proveedores para el Hogar & Jardín...
- Proveedores para el Hogar & Jardín...
- Proveedores para el Hogar & Jardín...
- +ARQUITECTURA, CONSTRUCCIÓN, PAISAJISMO & MARKETIN...
- Proveedores para el Hogar & Jardín...
- Proveedores para el Hogar & Jardín...
- Aircrack-ng: The Next Generation Of Aircrack
- Airpwn: A Wireless Packet Injector
- Best Hacking Tools
- Group Instant Messaging: Why Blaming Developers Is...
- Bypass Hardware Firewalls
- _Arquitectura & Construcción_
- Potao Express Samples
- BurpSuite Introduction & Installation
- inBINcible Writeup - Golang Binary Reversing
- How Do I Get Started With Bug Bounty ?
- Learning Web Pentesting With DVWA Part 4: XSS (Cro...
- Buscamos Proveedores de Productos para el Hogar...
- Grok-backdoor - Backdoor With Ngrok Tunnel Support
- Buscamos Proveedores de Productos para el Hogar...
- Part II. APT29 Russian APT Including Fancy Bear
- Blockchain Exploitation Labs - Part 2 Hacking Bloc...
- RFCrack Release - A Software Defined Radio Attack ...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- OWASP Web 2.0 Project Update
- Buscamos Proveedores de Productos para el Hogar...
- Structure Part I: The Basics
- Security Surprises On Firefox Quantum
- Snmpcheck
- DalFox (Finder Of XSS) - Parameter Analysis And XS...
- PHASES OF HACKING
- How To Run Online Kali Linux Free And Any Devices
- Linux Command Line Hackery Series: Part 1
- Solo las compañÃas más digitalizadas podrán fr...
- BeEF: Browser Exploitation Framework
- RED_HAWK: An Information Gathering, Vulnerability ...
- Buscamos Proveedores de Productos para el Hogar...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- Airpwn: A Wireless Packet Injector
- How To Control Android Phone From Another Phone Re...
- Spaghetti: A Website Applications Security Scanner
- Buscamos Proveedores de Productos para el Hogar...
- Top 5 Best TV Series Based On Hacking & Technology...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- ShellForge
- Part II. APT29 Russian APT Including Fancy Bear
- DOWNLOAD SQLI HUNTER V1.2 – SQL INJECTION TOOL
- Part I. Russian APT - APT28 Collection Of Samples...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- PKCE: What Can(Not) Be Protected
- How To Pass Your Online Accounts After Death – 3 M...
- Attacking Financial Malware Botnet Panels - SpyEye
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- New Printers Vulnerable To Old Languages
- How To Install And Config Modlishka Tool - Most Ad...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- Galileo - Web Application Audit Framework
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- CEH: Gathering Host And Network Information | Scan...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- Learning Web Pentesting With DVWA Part 6: File Inc...
- DEFINATION OF HACKING
- DEFINATION OF HACKING
- BeEF: Browser Exploitation Framework
- Ethical Hackers Platform: How To Install A bWAPP I...
- How To Install Metasploit In Termux
- Galileo - Web Application Audit Framework
- +ARQUITECTURA, CONSTRUCCIÓN, HABILITACIÓN, PAISAJI...
- Anyone Want To Go To GDC???
- Double CoC Play-test For Barbarossa
No hay comentarios:
Publicar un comentario