hi,
i was wondering could someone help.
i want my program to be able to input the values of a structure.
then using a pointer be able to print out and edit specific values of the structure.
ive made an attempt but i dont seem to be passing the pointer into my print function correctly. the instance of the struct has to be global so i wasnt sure if i should write it in or outside of the main class.
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
/* Structure declaration */
struct Struct1
{
short int shortInt;
long int longInt;
char string[64];
float floating;
};
struct Struct1 G_Instance; /* Structure variable declarations */
/* Initialize the structure variable from input data */
printf("Please enter a short integer value, an instance of Struct1: ");
scanf("%d", &G_Instance.shortInt ); /* Read the first value for the instance of struct1 */
printf("Please enter a long integer value, an instance of Struct1: ");
scanf("%ld", &G_Instance.longInt ); /* Read the second value for the instance of struct1 */
printf("Please enter a string, an instance of Struct1: ");
scanf("%s", &G_Instance.string ); /* Read the third value for the instance of struct1 */
printf("Please enter a floating point number, an instance of Struct1: ");
scanf("%lf", &G_Instance.floating ); /* Read the fourth value for the instance of struct1 */
struct Struct1 *pStruct;
pStruct = &G_Instance;
}
void printFunction(struct Struct1 *pStruct)
{
printf("/n %d ", pStruct->shortInt );
};