its been a while, but its comming back!


 
Thread Tools Search this Thread
Top Forums Programming its been a while, but its comming back!
# 1  
Old 05-01-2009
its been a while, but its comming back!

well, its been a while since I've done this programming business, so bear with me Smilie

back in college i took a C/unix course, and retained my old book. Recently I've gotten tired of having to calculate out my weight & balance every time i go flying...its a general pain (not really, but still Smilie ). So not having anything to do one day, i decided to dust that old thing off and see what i remembered!

well...i was a bit Smilie but i got there Smilie

here's a script file of my program that I've got so far, the problem is, after making my "choice" from the menu, it (as you can see) just sits and does nothing. Now if i 'comment' out the "ac" funciton, and manually define all of my data in the main body, the whole thing works, quite beautifully actually!! Smilie but still, for some reason, its liking to not get past the "ac" function. I can't see anything, but again, its been a while, let me know what you com up with!

thanks

-flyboy.


Code:

#include<stdio.h>


void menu (int* choice);
void ac (int choice, FILE* plane,int input[], int* MAX_WEIGHT, int* MAX_CG, int arm[]);
void getdata (FILE* plane, int input []);
int calc (int MAX_WEIGHT, int MAX_CG,int input[], int arm[], int* weight, int* balance);
void print( int weight, int balance, int oepration);

int main (void)
{

 
  int choice;
  FILE* plane;
  int input [15] = {0};
  int arm [6] = {0};
  int weight, balance = 0;

  int MAX_WEIGHT, MAX_CG;//upper limits of the weight and CG per plane
  int operation;

  menu(&choice);
  
  ac(choice, plane, input, &MAX_WEIGHT, &MAX_CG, arm);  // ac or a/c is short for Aircraft. Easier separation between function and file called plane
/*  plane = fopen("C172.DAT", "r");
  input[0] = 1491;
  MAX_WEIGHT = 2550;
  MAX_CG = 47;
*/

  getdata(plane, input);
  operation = calc (MAX_WEIGHT, MAX_CG,input, arm, &weight, &balance); // return value of '1' will be inside limits, '0' will be outside limits
  print(weight, balance, operation);

  return 0;

}


//=================================menu function================================


void menu (int* choice)
{
  printf("****************WELCOME!****************");
  printf("\n");
  printf("This program enabels you to calculate\n");
  printf("your weight and balance. Please enter\n");
  printf("a number and key <retrun> to make your\n");
  printf("selection from the menu below:\n");
  printf("\n");
  printf("1| Cessna 172\n");
  printf("2| Cherokee 6\n");
  printf("3| Piper Cub\n\n\n");
  printf("Enter your choice:");
  scanf("%d", choice);

 

 return;
}


//=====================================select data=========================

void ac (int choice, FILE* plane, int input[], int* MAX_WEIGHT, int* MAX_CG, int arm[])
{
  
 switch (choice)
     {
    case 1: plane =  fopen("C172.DAT", "r");
        input[0] = 1491;
        *MAX_WEIGHT = 2550;
        *MAX_CG = 47;
          arm[0] = 39;
          arm[1] = 35;
          arm[2] = 35;
          arm[3] = 74;
          arm[4] = 97;
          arm[5] = 116;
        break;
    case 2: plane =  fopen("Piper6.DAT", "r");
        input[0] = 1980 ;
            *MAX_WEIGHT = 3674 ;
        *MAX_CG = 96;
        arm[0] = 85;
        arm[1] = 85;
        arm[2] = 95;
        arm[3] = 118;
        arm[4] = 156;
        arm[5] = 179;

         
        break;
    case 3: plane =  fopen("Cub.DAT", "r");
        input[0] = 765.7;
        *MAX_WEIGHT = 1200;
        *MAX_CG = 23.7;
         arm[0] = 17;
         arm[1] = 9;
         arm[2] = 36;
         arm[3] = -18;
         arm[4] =  49;
        break;
      }
  
return;

}
//============================================getting data===============


void getdata (FILE* plane, int input[])
{
  char charin;
  int i = 1;

  while( (charin = fgetc(plane)) != EOF)
  {
   printf("%c", charin);
   while( (charin = fgetc(plane)) != '\n'  )
   {
     printf("%c", charin);
   }
    scanf("%d", &input[i]);
    i++;
  }
 

  return;
}



//===================calc data=========================


int calc (int MAX_WEIGHT, int MAX_CG, int input[], int arm[],  int* weight, int* balance)
{
  int moment;
  *weight = 0;

  for(int i = 0; i <=5; i++)
  {
    *weight += input[i] ;
    *balance += (input[i] * arm [i]); // one easy way to calculate the moment of inertia is to multiply the wieght by the arm and add it all up
  
  }//for

  printf("%d, %d", *weight , * balance);

  if ( (*weight > MAX_WEIGHT) || ((*balance / *weight) > MAX_CG) )
   return 0;
  else
    return 1;

}
//=========================print data======================


void print( int weight, int balance, int operation)
{

  if (operation == 0)
  {printf("\nI'm sorry, but your plane is not withing the flight envelope.");
   printf("\nPlease make adjustments so it is within proper weight and balance.\n");
  }
   else
   {
     printf("\n\nYour total weight is: %d\n", weight);
     printf("Your CG is: %d\n", (balance / weight ) );
   }

   return;
}//print results
]0;flyboy@csc-linux1:~[flyboy@csc-linux1 ~]$ gcc std-std=c99 term.c
]0;flyboy@csc-linux1:~[flyboy@csc-linux1 ~]$ a.out
****************WELCOME!****************
This program enabels you to calculate
your weight and balance. Please enter
a number and key <retrun> to make your
selection from the menu below:

1| Cessna 172
2| Cherokee 6
3| Piper Cub


Enter your choice:1
1
1
1
1
^C
]0;flyboy@csc-linux1:~[flyboy@csc-linux1 ~]$ exit
exit

Script done on Thu 30 Apr 2009 11:08:53 PM CDT

# 2  
Old 05-01-2009
You need to pass a pointer to plane instead of itself i.e.
Code:
void ac (int choice, FILE** plane,int input[], int* MAX_WEIGHT, int* MAX_CG, int arm[]);

# 3  
Old 05-01-2009
I LOVE YOU!!!!!!!


hahaha, thanks alot, I knew it had to be something simple. I was trying to remember if the file declarations were like array's in that you don't have to do that, but after you said that i did some digging (just for giggles) and i did find that the book mentioned that.

program works like butta now, I'll post a script tomorow!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - output comming strange: for operator ~ and == .

Hi awk experts, I am getting a strange output , may be it is normal but I am unable to comprehend, When Using == operator it is showing correct: # ls -l | awk '{for (i=0;i<=NF;i++) if ( $i =="info" )print $1,$6,$7,$8,$9}' drwx------ Jan 17 10:44 info But When using ~ (equal )... (4 Replies)
Discussion started by: rveri
4 Replies

2. Shell Programming and Scripting

Output is not comming as expected

Hi All, I am in middle of one script. I want output in the form of xls file. There are 4 fields - user name, email Id, full name, date of birth. I want these details to get in seperate columns. But, i am getting it in the single cell and as like a paragraph.:mad: Please suggest me some... (8 Replies)
Discussion started by: Agupte
8 Replies

3. Solaris

Oracle db is not comming up..

Hi, We need to the file(blocks) should be unlimited...tried ulimit -f unlimited.. but still its not working..this is solaris 9 system. Please help me out.this is production server... orapd1 2% ulimit -a time(seconds) unlimited file(blocks) 1000000... (2 Replies)
Discussion started by: bpsunadm
2 Replies

4. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

5. IP Networking

Back-to-Back Connection using HBAs

Hi every body, Is it possible to connect two servers Back-to-Back (Point-to-Point) using HBA adapters & using Fiber. Note it is direct connection & there is no switches between the servers. I'm concern about using HBA adapters, it is possible or not. Thanks in advance. :) (3 Replies)
Discussion started by: aldowsary
3 Replies

6. AIX

back to back printing in UNIX

Hi , Can you suggest me how to back to back printing in UNIX? Is there any way? Kindly advise. Regards Vijaya Amirtha Raj (3 Replies)
Discussion started by: amirthraj_12
3 Replies

7. Shell Programming and Scripting

back up

hi all i need to transfer files from one server to another,but i have to make up a backup with a datestamp on the destination server beore i move the new files from the source to the destination server. example source server destination server a.sun a.sun b.sun ... (0 Replies)
Discussion started by: bkan77
0 Replies

8. HP-UX

Help about back up

Hi this is Ramana.sv new to this group, please help me about my question, i am using HP-UX11.11i with oracle 10G this server is in india and i have another server in US with same HP-UX with oracle10G, what i want is i want to rename the local database in local HP server and copy the database from... (0 Replies)
Discussion started by: mcseramana
0 Replies

9. UNIX for Advanced & Expert Users

problem with comming out on internet

Hi I am runnig Sun solaris 9 on Intel. I have problem with comming out on internet, i can ping the other machine that are in the network. what should i do? /stefan (1 Reply)
Discussion started by: steffa
1 Replies
Login or Register to Ask a Question