Thread: Displaying Data in C programmming

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    1

    Displaying Data in C programmming

    Hey guys, I am having a small problem with my code, see below.

    /************************************************** *************
    * RADAR_SYSTEM *
    * VERSION: 1.1 *
    * AUTHOR: 205123 *
    * DATE: 23/03/04 * *
    /************************************************** ************/

    #include <stdio.h>
    #include "radar_gen.h"
    #include <math.h>


    int max_aircraft=2;

    int main()

    {
    int i,j;
    float aircraft_distance,aircraft_range,aircraft_x_pos,ai rcraft_y_pos,aircraft_altitude,e;



    struct radar_data aircraft[30];

    struct ship_data ship;
    for(j=1; j<10; j++)
    {
    wait_for_next_scan(1.00);
    for(i=1; i<=1; i++)
    {


    get_radar_data(&aircraft[i]);

    get_ship_data(&ship);

    e=aircraft[i].elevation*(3.14/180);

    aircraft_range=aircraft[i].range * 25/1000;

    aircraft_distance=aircraft_range * cos(e);

    aircraft_x_pos=ship.x_pos + aircraft_distance;

    aircraft_y_pos=ship.y_pos - aircraft_distance * cos((ship.heading) + (aircraft[i].bearing));

    aircraft_altitude= (sin(e) * aircraft_range)*1000;

    //printf("-----------------------------------------------------------------");
    //printf("\nShip Data:\n-----------------------------------------------------------------");
    //printf("\nThe ship's heading is:\t\t|\t%lf km\t\t|\n",ship.heading);
    //printf("\nThe ship's x pos is:\t\t|\t%lf km\t\t|\n",ship.x_pos);
    //printf("\nThe ship's y pos is:\t\t|\t%lf km\t\t|\n\n",ship.y_pos);
    //printf("-----------------------------------------------------------------");
    printf("\nAircraft Data:\n\n");
    printf("IFF Code\t|Altitude\t|X Position\t|Y Position |\n------------------------------------------------------------|\n");
    printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft[i].IFF_code,aircraft_altitude,aircraft_x_pos,aircraf t_y_pos);
    printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft[i].IFF_code,aircraft_altitude,aircraft_x_pos,aircraf t_y_pos);



    //printf("\nThe aircraft's bearing is:\t|\t%lf degrees\t|\n",aircraft[i].bearing);
    //printf("\nThe aircrafts range is:\t\t|\t%d range gates\t|\n",aircraft[i].range);
    //printf("\nThe aircrafts elevation is:\t|\t%lf degrees\t|\n",aircraft[i].elevation);
    //printf("\nThe aircrafts distance:\t\t|\t%f km\t\t|\n",aircraft_distance);
    //printf("\nThe aircrafts IFF code is:\t|\t%d\t\t\t|\n",aircraft[i].IFF_code);
    //printf("\nThe aircrafts x pos is:\t\t|\t%f km\t\t|\n",aircraft_x_pos);
    //printf("\nThe aircrafts y pos is:\t\t|\t%f km\t\t|\n",aircraft_y_pos);
    //printf("\nThe Aircrafts altitude is:\t|\t%f meters\t|\n",aircraft_altitude);
    }
    }
    }


    What the code does is reads from a file that provides radar data on aircrafs. Doing a few calculation, I can figure out the x, y positions of the planes and the altitude of them. Now because there can be more than one plane, (defined in Max_aircraft) you can get any number of up to 20 aircraft in one scan. What I am trying to do is display all the aircraft details in one table per scan. What I have got ay the moment is every scan, each aircraft details is displayed in a seprate table statrement. I am also trying to get it so the y cooridents are sorted in accending order, I now you have to use a bubble sort in the array, but am a little unsure how it is written in the code. If anyone has got any idea, I would be thankful.
    Cheers

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    CODE /CODE it man
    Code:
    /************************************************** *************
    * RADAR_SYSTEM *
    * VERSION: 1.1 *
    * AUTHOR: 205123 *
    * DATE: 23/03/04 * *
    /************************************************** ************/
    
    #include <stdio.h>
    #include "radar_gen.h" 
    #include <math.h>
    
    
    int max_aircraft=2;
    
    int main()
    
    { 
            int i,j;
            float aircraft_distance,aircraft_range,aircraft_x_pos,ai rcraft_y_pos,aircraft_altitude,e;
    
    
    
            struct radar_data aircraft[30];
    
            struct ship_data ship;
            for(j=1; j<10; j++)
            {
                    wait_for_next_scan(1.00);
                    for(i=1; i<=1; i++)
                    {
    
    
                    get_radar_data(&aircraft[i]);
    
                    get_ship_data(&ship);
    
                    e=aircraft[i].elevation*(3.14/180);
    
                    aircraft_range=aircraft[i].range * 25/1000;
    
                    aircraft_distance=aircraft_range * cos(e);
    
                    aircraft_x_pos=ship.x_pos + aircraft_distance;
    
                    aircraft_y_pos=ship.y_pos - aircraft_distance * cos((ship.heading) + (aircraft[i].bearing));
    
                    aircraft_altitude= (sin(e) * aircraft_range)*1000;
    
                    //printf("-----------------------------------------------------------------");
                    //printf("\nShip Data:\n-----------------------------------------------------------------");
                    //printf("\nThe ship's heading is:\t\t|\t%lf km\t\t|\n",ship.heading);
                    //printf("\nThe ship's x pos is:\t\t|\t%lf km\t\t|\n",ship.x_pos);
                    //printf("\nThe ship's y pos is:\t\t|\t%lf km\t\t|\n\n",ship.y_pos);
                    //printf("-----------------------------------------------------------------");
                    printf("\nAircraft Data:\n\n");
                    printf("IFF Code\t|Altitude\t|X Position\t|Y Position |\n------------------------------------------------------------|\n");
                    printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft[i].IFF_code,aircraft_altitude,aircraft_x_pos,aircraft _y_pos);
                    printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft[i].IFF_code,aircraft_altitude,aircraft_x_pos,aircraft _y_pos);
    
    
    
                    //printf("\nThe aircraft's bearing is:\t|\t%lf degrees\t|\n",aircraft[i].bearing);
                    //printf("\nThe aircrafts range is:\t\t|\t%d range gates\t|\n",aircraft[i].range);
                    //printf("\nThe aircrafts elevation is:\t|\t%lf degrees\t|\n",aircraft[i].elevation);
                    //printf("\nThe aircrafts distance:\t\t|\t%f km\t\t|\n",aircraft_distance);
                    //printf("\nThe aircrafts IFF code is:\t|\t%d\t\t\t|\n",aircraft[i].IFF_code);
                    //printf("\nThe aircrafts x pos is:\t\t|\t%f km\t\t|\n",aircraft_x_pos);
                    //printf("\nThe aircrafts y pos is:\t\t|\t%f km\t\t|\n",aircraft_y_pos);
                    //printf("\nThe Aircrafts altitude is:\t|\t%f meters\t|\n",aircraft_altitude);
                    }
            }
    }
    Last edited by sand_man; 05-11-2004 at 08:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Replies: 3
    Last Post: 04-18-2008, 10:06 AM
  3. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  4. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM