I have wrote this program to do i of 6 thing to

1) Initialise: Read static data from a file and
a) store in appropriate data structures at run time
b) sort into alphabetic order for subsequent display in the grid.

2) Menu: A menu to support the following:

Have to use a switch statement for menu and also validation for menu.

My program should display an error message when the user input an city that it not specified within the array or my file. Also it should loop if they tpe in a mber or a incoorect place for the destination.

a) Display Chart: Display the grid like the one in a code but trying to open a file with the towns in and there distance.

b) CalcDistance: Allow input of a Journey between two points via up to 10intermediate stops.

c) Totalcost: Allow input of two points and calculate the cost of the journey at 40ppm up to 100 miles (or km) and 30ppm for miles (or km) in excess of this.

d) Exit: to exit the program.

3) PlaceSearch: search for valid places during input of route details

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "node.h"


struct Chart
{
char Town[10][10];
int Distance[10][10];
};

Chart chart= 
{
 { "London", "Bath", "Cardiff", "Carlisle", "Durham", "Exeter", "Leeds", "Norwich", "Truro", "York" },
   { 0, 23, 12, 89, 456, 123, 46, 732, 345, 123 },
   { 23, 0, 46, 234, 123, 46, 89, 234, 567, 90 },
   { 12, 46, 0, 767, 456, 46, 234, 123, 732, 35 },
   { 89, 234, 767, 0, 732, 32, 48, 67, 98, 100 },
   { 456, 123, 456, 732, 0, 234, 46, 89, 89, 732 },
   { 123, 46, 46, 32, 234, 0, 123, 46, 123, 234 },
   { 46, 89, 234, 48, 46, 123, 0, 46, 89, 19 },
   { 732, 234, 123, 67, 89, 46, 46, 0, 123, 732 },
   { 345, 567, 732, 98, 89, 123, 89, 123, 0, 78 },
   { 123, 90, 35, 100, 732, 234, 19, 732, 78, 0 },
};

int ReadChart(const char Towns[],const Chart* chart )
 {
  FILE *fp;

     fp = fopen("Towns.txt", "r");
     if (fp == NULL)
                                                                                                  
    return 0;
 else 
  {
    size_t res = fread(chart, sizeof(Chart), 1, fp);
    fclose(fp);
    
    return res;
  }
 }

int WriteChart(const char Towns[], const Chart* chart)
 {
  FILE *fp;

  fp = fopen("Towns.txt", "w");
  if (fp == NULL)
  return 0;
 else 
 {
  size_t res = fwrite(chart, sizeof(Chart), 1, fp);
  fclose(fp);
  return res;
 }
}               

int main(void)
{
 char Distance;
 int  valid_input;
 int row,col;
 char des1,des2,des3;
 int menu;             /* Holds all chices open to the user */
 double total = 0.00;           /* the result of the calculation */

 
  printf("\n\nWhat would you like to do?\n\n");    /* WRITE instructions */
  printf("\t1 = Display Mileage chart from text file\n");
  printf("\t2 = Input of a Journey between two points via up to 3 intermediate stops\n");
  printf("\t3 = Display total cost of journey at 40 ppm up to 100 miles and 30ppm for mileas in excess of this\n");
  printf("\t4 = Exit program\n");
  printf("\n\nPleas make your selection now:\n\t");
  scanf("%d",&menu);                   /* READ calculation type */
    
  valid_input = 0;
     while( valid_input == 0 )
        {
           printf("\t Please enter first destination point\n");    
           printf("%s",des1);
           printf("\t Please enter second destination point\n");    
           printtf("%s",des2);
           printf("\t Please enter thrid destination point\n");    
           printf("%s",des3);
           
	            else  
	            {
	            printf("\tError: Invalid \n");    
	            }
	      }
   switch (menu != 4)
   {
    case 1:   
    FILE *infile;
    infile = fopen("Towns.dat", "r");       // using relative path name of file
	       if (infile == NULL)
            {
             printf("Unable to open file."); 
            }
               
              for(row=1; row<11;row++) // reads in the data into the array in 2 loops 
               {                    
                      for(col=1;col<11;col++)
                      {
                         fscanf(infile,"%d", chart[row-1][col-1]);
                        
                      } 
               }      
                      
               for(row=0; row<10;row++) 

               {                  
                       printf("\n\n");   
                      for(col=0;col<10;col++)
                      {
                         printf("%-2d ",chart[row][col]);
                      }
                     
               }
               	printf("\n\n continue?");
	             scanf("%d", &menu);
               
 
  break;


  case 2:
    prinf("\t Please enter first destination point\n");    
    printf("%s",des1);
    prinf("\t Please enter second destination point\n");    
    printf("%s",des2);
    prinf("\t Please enter thrid destination point\n");    
    printf("%s",des3);
 
  break;

   case 3:
      if (Distance => 100) 
     {
      total= 0.40*100;
     } 
    
     if (Distance < 100)
     {
      total= 0.30*100;
     }
   break;

   case 4:
     printf("Thank you for using my program");
   break;

   default: 
      printf("Invalid option selected\n");  
}
 
 int search (node *root, int key)
 {
  if ( root != NULL) 
  {
    if ( key == root->data )
      return 1;
    else if ( key < root->data )
      return search ( root->left, key );
    else  if ( key > root->data ) 
      return search ( root->right, key );
  }

  return 0;
 }   
}

I use Miracle C to compile my program and unix.

I am sorry for pesting you with this huge problem but i have tried other methords but failed and i was wondering if you could help me out please thank you

You forgot to ask your question. Also, if you want us to be able to compile the code, you'll have to include the contents of node.h.

sorry
Here the node.h

/* utilize an ifndef/define mechanism, so nodes will be define exactly once */
#ifndef _NODE_H
#define _NODE_H

/* Maximum length of names */
#define strMax 90

/* Define the node structure itself */
struct node
{ 
  char data [strMax];
  struct node * left;
  struct node * right;
};

#endif

Questions

Why dose my prgram work in mirale C and how do i get it to worin unix because it wont work in unix?

Here my Question

My program has some bugs and i sovled the bugs in mircale C but i cant get it to work in unix i have put all the files into unix but i still cant get it to work in unix?

any help would be grateful. Thanks i have modified the code countless time but still no change can anyone offer there serves to help please.

do you want the txt file or not

do you want the txt file or not

That would be a good idea. If the textfile has a lot of similair lines, just post the first few lines.
Also: Define 'bugs'. What output are you expecting and what IS the output. When do the bugs occur?

Here the txt file

London Bath Cardiff Carlisle Durham Exeter Leeds Norwich Truro York
London 0 114.66 151.22 309.14 269.11 195.90 195.33 117.87 284.74 209.43
Bath 115.16 0 55.95 288.37 293.02 86.41 219.24 235.72 175.25 233.34
Cardiff 151.61 56.17 0 303.39 308.04 109.81 234.26 272.17 198.65 248.36
Carlisle 309.35 288.23 303.39 0 73.73 348.15 117.24 280.36 436.99 116.36
Durham 269.78 293.42 308.58 73.75 0 353.34 82.10 239.13 442.17 75.13
Exeter 196.04 85.71 109.14 347.90 352.56 0 278.78 316.61 87.49 292.88
Leeds 196.11 219.75 234.91 117.17 80.32 279.67 0 171.06 368.50 24.76
Norwich 118.49 235.75 272.31 283.26 241.67 316.99 173.45 0 405.83 182.76
Truro 284.56 174.22 197.65 436.42 441.07 87.07 367.30 405.12 0 381.39
York 212.84 236.48 251.64 116.53 74.93 296.40 24.21 180.26 385.23 0

first off it should display my menu it ask the user:

1) dispaly mileage chart from text file
2) create file to put the array towns and distances in a text file
3) Input started location and finish location i.e. Bath to london
4) Display other mileage chart from array
5) Display total cost of journey at 40 ppm up to 100 miles and 30ppm for mileas in excess of this
6)Exit prgram and dispaly goodbye message

It has no errors in miracle C but it dose have errors in Unix unix complains about all my codeing here what it compalins about
Varble not declared which they are
Dosent liket the pointer in tihs piece of codings

int ReadChart(const char Towns[],const Chart* chart )

int WriteChart(const char Towns[], const Chart* chart

Exception found "*" expects "," or "."
Exception found printf using Char should be int but i want the user to type in london to bath and i used scanf but it dosent like that.

I have tried to modifiy my coding but it dosent like youd have to run it an see the errors for yourself cus there that many errors when i compile it in unix i am going mad. I dont understand why it works in mirrcle C and not unix. but i have to get it to run in unix.

how do iget get above to work in unix

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.