The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Back-to-Back Connection using HBAs aldowsary IP Networking 3 11-28-2008 10:21 PM
back to back printing in UNIX amirthraj_12 AIX 3 05-06-2008 08:42 AM
Help about back up mcseramana HP-UX 0 07-17-2007 09:54 AM
problem with comming out on internet steffa UNIX for Advanced & Expert Users 1 09-13-2004 09:30 AM
Back up's macdonto UNIX for Dummies Questions & Answers 3 08-01-2002 11:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-01-2009
flyboy flyboy is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
its been a while, but its comming back!

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

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 ). 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 but i got there

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!! 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 (permalink)  
Old 05-01-2009
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
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 (permalink)  
Old 05-01-2009
flyboy flyboy is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0