| | |
Displaying Data in C programmming
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2004
Posts: 3
Reputation:
Solved Threads: 0
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,aircraft_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);
}
}
}
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
/***************************************************************
* 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,aircraft_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);
}
}
}
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
![]() |
Similar Threads
- Saving and displaying data on datagrid! (VB.NET)
- After migration ASP.Net 1.1 to 3.5: TreeView control is not displaying data in hierar (ASP.NET)
- problem in displaying data from mysql table.. (PHP)
- Displaying data from a MySQL db using php (PHP)
- Problem in displaying data from DB (PHP)
- Displaying data from database (PHP)
- displaying data onto a web page (ASP.NET)
Other Threads in the C Forum
- Previous Thread: sorting file
- Next Thread: programming c in unix
| Thread Tools | Search this Thread |
* ansi api append array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation threads unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





