Jump to content

[SOLVED] [C] Regarding structures and scanf


thomashw

Recommended Posts

Can someone explain how to use scanf with a structure?

 

Here's the code I'm trying to use, and it's not working:

 

#include<stdio.h>

typedef struct hey{
double x;
double y;
} hey;

int main()
{

hey whatsup;

scanf( "%f", &whatsup.x );
printf( "%lf", whatsup.x );

}

 

Whatever I enter, the printf function prints "0.000000".

Link to comment
https://forums.phpfreaks.com/topic/129014-solved-c-regarding-structures-and-scanf/
Share on other sites

It looks to me like one can't create a reference to a variable in a structure.  (Maybe someone who knows C can tell us how?)

 

 

Why not just do

 

double tmp;

scanf("%f", tmp);

whatsup.x = tmp;

 

 

Edit:  Oh this is solved....  Hrmm never mind.  Just of curiosity, how did ya do it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.