Looking for some help

This is a discussion on Looking for some help within the C Programming forums, part of the General Programming Boards category; Rather than try to explain my question, I am gonna copy and paste my assignment sheet to avoid confusion. 2. ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    1

    Looking for some help

    Rather than try to explain my question, I am gonna copy and paste my assignment sheet to avoid confusion.


    2. Practice with arrays and file I/O. Write a program that will read in the complex values stored in the
    file “impedance.txt” that we used in class, writing a new file which contains the magnitude and angle
    corresponding to each complex value.
    Now, although you do not NEED to use arrays to do this (you could read in one value, then write its
    magnitude and angle before going to the next value) I want you to get some practice with arrays!
    Might as well practice structures too.
    So... read the data into an array of complex values. Define a new struct that would hold a magnitude
    and an angle. Create an array of that new struct type, and write a loop to fill it with the magnitudes
    and angles from the original data array. Finally, write all those magnitudes and angles into a file, and
    print that file as your results.
    My question is, while I know how to read a file and store it into an array, I am a little confused on setting up a structure to hold a magnitude and angle. Then creating another array of that new struct type and write a loop to fill it with the magnitudes and angles from the original data array.

    If anyone can assist and giving me a starting point on this, I would appreciate it greatly.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, since you're supposed to learn structs, I would suggest you start by learning structs. What part of defining a struct is confusing you?

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    OK here is a piece of one of my progs were it defines an array of structures.
    Its a bit more compliceted than need as the elements in the structure are themselves
    arrays (tabname and pid) so yours may be simpler. OK I just added an angle

    Code:
    typedef struct {
    		char tabname[20];
    		int pid[11];
                    int angle;
    		} IDLIST;
    		
    IDLIST tab[1000];
    
    
    strcpy(tab[27].tabname,"tabletwentyseven"); //example of access of an element
    
    tab[23].angle=45;

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21