By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,500 Members | 2,809 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,500 IT Pros & Developers. It's quick & easy.

struct in c

P: 18
Hi !

I'm trying to build a program that can convert polar to polar to cartesian using struct variables1 but here i came across a problem witch is when i scanf the values of (a&b) it telles me that i have to enter yet a another one !!

the code is !

Expand|Select|Wrap|Line Numbers
  1. #pragma warning(disable:4996)
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. void PolarTo_Cartesian(double r, double d, double *q, double *u);
  6.  
  7. struct MyStruct
  8. {
  9.     double x;
  10.     double y;
  11. }; 
  12.  
  13. int main(){
  14.  
  15.     printf("enter ur cord\n");
  16.  
  17.     struct MyStruct a;
  18.     struct MyStruct b;
  19.  
  20.     a.x; // puting value to x  
  21.     b.y;
  22.  
  23.    scanf("%lf\n", &(a.x));
  24.    scanf("%lf\n", &(b.y));
  25.  
  26.     PolarTo_Cartesian(a.x, b.y, &(a.x), &(b.y)); // to store the address so i can change its value !!
  27.    printf("the valus is (%lf,%lf)\n",a.x,b.y);
  28.  
  29.     system ("pause");
  30.  
  31.     return 0;
  32. }
  33. void PolarTo_Cartesian(double r, double d, double *q, double *u) {
  34.  
  35.     *u = r*(sin(d));
  36.     *q = r*(cos(d));
  37.  
  38. }
  39.  
Nov 17 '15 #1
Share this Question
Share on Google+
2 Replies


P: 22
replace the scanf with this that is remove the newline.
Expand|Select|Wrap|Line Numbers
  1.    scanf("%lf", &(a.x));
  2.    scanf("%lf", &(b.y));
  3.  
Nov 17 '15 #2

P: 18
sorry dont really understand what u mean
Nov 17 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.