How To Use Scanf With Struct
-
03-04-2005 #1
Registered User
input from scanf into structure, how?
Hi, I am making a uncomplicated program that asks the user to input 2d points and the program will perform various functions.
This is what I have so farLawmaking:
#include <stdio.h> struct point2D { float x; bladder y; }; int main() { point2D pa,atomic number 82; printf("Please enter the first point: "); scanf("%f" "%f", &pa.x, &pa.y); printf("Please enter the 2d indicate: "); return(0); }
i get a runtime error and it says floating point is not loaded.
Am I using the structure wrong or is it the scanf?Thanks
-
03-04-2005 #ii
ATH0
You could always exercise a forum search for the bulletin, or peradventure look at what the first hit on a Google search gives yous.
Quzah.
Hope is the outset step on the route to thwarting.
-
03-04-2005 #3
Registered User
you need to declare insances of the structure. You have correctly created the construction, but need instances.
And then....
Code:
struct point2d pa; struct point2d lead;
Also change theCode:
scanf("%f" "%f".......
Code:
scanf("%f %f"......
Terminal edited by computerfreaks; 03-04-2005 at 08:eighteen AM.
-
03-04-2005 #four
ATH0
Really, no you don't have to. 2 string literals volition be concatenated into a single literal at compile time. Furthermore, they take alleged an example of their structure, or at least if they're compiling as C++ they have:
Code:
struct point2D { float x; float y; }; int main() { point2D pa,lead;
Neither of these issues are really what they're posting about however.
Quzah.
Promise is the starting time pace on the road to disappointment.
-
03-04-2005 #5
Registered User
I stand corrected..... however if this is c++ and so surely the bulletin should exist posted in the c++ forum??
So are you maxim that
scanf("%f""%f", &var1, &var2);
is accepted? ok... just tested and it is, but nonetheless, it seems like bad practice to put this...
therefore the code should exist (if C ):
Lawmaking:
#include <stdio.h> struct point2D { bladder x; float y; }; int main() { struct point2D pa,pb; printf("Please enter the first point: "); scanf("%f" "%f", &pa.ten, &pa.y); printf("Delight enter the 2nd point: "); system("pause"); return(0); }
-
03-04-2005 #6
ATH0
Sure, it should be compiled as C. However, since they didn't say they were getting any other errors, such as:
suchas.c: In office `master':
suchas.c:11: error: `point2D' undeclared (kickoff apply in this role)
suchas.c:eleven: error: (Each undeclared identifier is reported only once
suchas.c:xi: error: for each function information technology appears in.)
suchas.c:11: error: parse error before "pa"
suchas.c:14: fault: `pa' undeclared (first use in this function)Quzah.
Hope is the get-go stride on the road to disappointment.
-
03-04-2005 #seven
Registered User
this form seem clearer to me.
Lawmaking:
#include <stdio.h> typedef struct { float x; float y; }point2D; int main() { point2D pa; printf("Please enter the first point: "); scanf("%f" "%f", &pa.ten, &pa.y); printf("Please enter the second point: "); system("pause"); return(0); }
-
03-04-2005 #8
Just Lurking
Originally Posted by ronenk
https://cboard.cprogramming.com/showthread.php?p=322171[Which is the same thing y'all'll discover if you follow quzah's link.]
7. It is easier to write an incorrect program than empathise a right one.
twoscore. At that place are two ways to write error-costless programs; only the third i works.*
-
03-04-2005 #9
and the hat of int overfl
> scanf("%f""%f", &var1, &var2);
> is accepted?
Yes, the compiler will automatically join "how-do-you-do " "world" into "howdy world" for you.Non a lot of use here, but dead handy if y'all're trying to create some assistance text and yous don't want your source code to await a mess.
How To Use Scanf With Struct,
Source: https://cboard.cprogramming.com/c-programming/62606-input-scanf-into-structure-how.html
Posted by: ratliffpeammeak.blogspot.com
0 Response to "How To Use Scanf With Struct"
Post a Comment