I can't seem to pass a struct address to a function. My program "stops working" when it gets to the scanf statement of the getReady function.

Purpose: This code will explore passing a data structure
address to a function.
#include <stdio>
#include <stdlib>

struct things{
	char knife;
	char pen;
	char wallet;
	char keys;

int getReady(struct things *t,char x);

void main()
char ready;
char r;
struct things *t;

ready =getReady(t,r);
	if (ready == 'y')
		printf("\nLet's go!!!");

int getReady(struct things *t,char x)
	printf("\nHave you got your wallet? y/n: ");
	printf("\nHave you got your pen? y/n: ");
	if((t->knife == 'n') || (t->pen == 'n')){
		printf("\nYou're not ready...");
		x = 'n';
		x = 'y';
	return x;

You defined your struct, and made a pointer to it, but I don't see an actual struct being declared.

Also, scanf() needs a getchar() after each instance, if you want to keep getting char's from it. Need to pull the newline char, off the keyboard buffer.


Scanf() %c requires a pointer to a character, but all you are passing is a char itself. Change t->wallet like this: scanf("%c", &t->wallet); The the same with other scanf() functions.

Thank you!!! ...Ancient One

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.