473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help about changing typedef in structures..C programming help

17
hi mate..
i want to change my struct text in
Expand|Select|Wrap|Line Numbers
  1. typedef struct{double r;
  2. double i;} COMPLEX;
assume i want to change it to normal one without the typedef thing and do it like this
Expand|Select|Wrap|Line Numbers
  1.  struct COMPLEX
  2. {double r;
  3. double i;};
]


now i got errors when i want to convert my codes here...
can anyone help me if i want to change the first to the second in my following codes
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. typedef struct{double r;
  4. double i;} COMPLEX;
  5. COMPLEX c_add(COMPLEX za, COMPLEX zb);
  6.  
  7. main()
  8. {
  9.     COMPLEX z1, z2, z3, *pz;
  10. /******************************************************************
  11.  
  12. * Get two complex numbers *
  13. ******************************************************************/
  14.  
  15. printf("enter the values of z1 and z2:\n z1?:\n");
  16. scanf("%lf%lf",&z1.r, &z1.i);
  17. printf("z2:\n");
  18. scanf("%lf%lf",&z2.r,&z2.i);
  19.  
  20. pz = &z3;
  21. *pz = c_add(z1,z2);
  22. printf("%lf + %lfi\n",pz->r,pz->i);
  23. }
  24. /****************************************************************** 
  25.  
  26. * Returns sum of complex numbers za and zb 
  27. ******************************************************************/
  28. COMPLEX c_add(COMPLEX za, COMPLEX zb)
  29.  
  30. COMPLEX sum; 
  31.  
  32. sum.r = za.r + zb.r;
  33. sum.i = za.i + zb.i;
  34. return (sum);
  35.  
  36. }
Is it possible for this code or not?need help please..
Oct 12 '08 #1
4 1578
JosAH
11,448 Expert 8TB
If you remove the typedef the name of your struct type is just 'struct COMPLEX'.
You have to set the type of your complex variables to 'struct COMPLEX' instead
of just 'COMPLEX'. Why you don't want to use a simple typedef is beyond me.
note that in C++ you *can* use 'COMPLEX' instead of 'struct COMPLEX'.

kind regards,

Jos
Oct 12 '08 #2
Is it possible for this code or not?need help please..
Yes it is. Write struct before COMPLEX everytime a COMPLEX structure is declared(meaning in lines 9 and 31 write: struct COMPLEX ...).
Oct 12 '08 #3
MyRedz
17
thanks for the reply..i was just experimenting if it is possible..well
i am trying the hard way i guess.will inform ya if this code conversion works..
Oct 12 '08 #4
donbock
2,426 Expert 2GB
I don't understand what you're trying to accomplish. Would the following be useful to you?
Expand|Select|Wrap|Line Numbers
  1. typedef struct complex {
  2.    double r;
  3.    double i;
  4. } COMPLEX;
The (dis)advantage here is that you can refer to either 'struct complex' or 'COMPLEX'. Using two names for the same type is usually a bad idea because it can really confuse anybody who tries to understand the code. In this case, the (dis)advantage is that the program will continue to work as you implement the conversion from COMPLEX to 'struct complex'. On the other hand, without the prompting of compiler warnings you might miss a few locations that need to change.
Oct 12 '08 #5

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

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
11
by: Alfonso Morra | last post by:
Hi, I have the ff data types : typedef enum { VAL_LONG , VAL_DOUBLE , VAL_STRING , VAL_DATASET }ValueTypeEnum ;
2
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
5
by: aaragon | last post by:
Hello everybody, I appreciate your taking the time to take a look at this example. I need some help to start the design of an application. To that purpose I'm using policy-based design. The...
8
by: Chris LaVelle | last post by:
I don't know the easiest way to explain this so, I'm going to give an example of how it is today....and what I'm trying to accomplish. in the header... typedef struct XXX_ELEMENT_tag { UINT8 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.