NEWS: Total Picture Views: 147066 | Total Article Views: 155659 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. How to read a JSON and work with it | 3. PickUpThings with Becker Robot | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Using A Pointer To Read An Object C

Description:

In this example I will be showing how to use a pointer to read a object (Structure)

Code:

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <string.h>

typedef struct
{
	char title[30];
	char author[30];s
	char publisher[30];
	int publicationYear[4];
} Book;

int main(int argc, char *argv[]){
	Book book;
	Book  *bookptr;

	printf("Please enter a title:\n");
	gets(book.title);
	printf("\nPlease enter an author:\n");
	gets(book.author);
	printf("\nPlease enter a publisher:\n");
	gets(book.publisher);
	printf("\nPlease enter a publication year:\n");
	scanf("%d",&book.publicationYear);

	bookptr = &book;

	printf("%s\n", bookptr->title);
	printf("%s\n", bookptr->author);
	printf("%s\n", bookptr->publisher);
	printf("%d\n", bookptr->publicationYear);

	system("pause");
}
Attachments: None

Tags: Pointer Print gets scanf structure

Total Views: 776

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/03/15 and updated on 02/04/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.