0

I have never programmed in C and have not programmed in C++ for a little while and either way, I am still learning.

I am writing a program in C and am converting a MATLAB program to this C program. I have a lot of variables from MATLAB that are cartesian coordinates, X Y Z, of points. Is there a variable type I could use built into C? I need to subtract different points and also do other operations on them. Any suggestions?

Thanks,
DemiSheep

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

Ok I have another question. I want to make sure this is a good idea. I have an object with several characteristics. Say it's a car and the car has several different parameters.

Parameters:

Position on map
Altitude (sea level?)
Start position
End Position

Can I use a struct or union (or both?) to have all these parameters inside the car "object" and update the parameters in the object like you would if it was it's own class in like C++ or Java?

Like if I want to calculate the distance the car traveled from the start position to its current position in like a Cartesian plane I could do something like:

distantTraveled = car.position - car.startPosition

Thanks,
DemiSheep

0

Exactly right. Structs are used in C, to combine related variables, into one object.

0

you don't want to use a union in your program because you need the value of all the object at the same time. unions won't allow that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.