a carrige-return character was encounterd; loads of errors helpp please :)
i have been making my program on dev c++ and well i have to have it running on the school unix server for a demo and well im getting alot off a really odd error.
this is my code
Code:
// C Programming Assingment
// Header Files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//prototypes
int menu(void);
int strcmp( const char *str1, const char *str2 );
void read(char place[11][11], int dist[10][10]);
void display(char place[11][11], int dist[10][10]);
int main (void)
{
//Variables
char place[11][11];
int dist[10][10];
int row, col, i, numstops, end, wrong, flag, option;
double price;
int stops[3], point[2];
char pos[2][16];
char stopname[3][16];
// Calls upon the read function
read(place,dist);
while(end !=1) //will loop until end = 1
{
option = menu(); // calls upon the menu
switch(option) // using a switch statement for the value of option
{
case 1: display(place,dist); // calls upon the display function
break;
case 2:
for(i=0;i<2;i++) // loops round twice allowing the input of 2 points
{
if(wrong!=1) // if wrong is 0 it will out put the following
{
if(i==0){printf("\n Please enter your Start point: ");} // input first point
if(i==1){printf("\n Please enter your Finishing point: ");} // input first point
}
wrong=0; // set wrong to 0
scanf("%16s", pos[i]);
size_t x;
flag = 0; // sets flag to 0 so place is invalid until found
for(x = 0; x < sizeof(place); x ++)
{
if(strcmp(place[x+1], pos[i])==0)
{
// place found
point[i] = x; // point at position i is set to the value of x
flag=1; //sets flag as 1 because its a valid place
}
}
if(flag==0) // place not found
{
printf("\n Invalid place name please re enter: ");
i--; // decrements i by 1 sooo it will loop round again
wrong=1; // sets wrong to 1 so the ask for start or finsh point is not asked for again
}
}
printf("\n Please Enter the number of stops 0-3: ");
scanf("%5d",&numstops);
while(numstops >3 || numstops <0) // validates that numstops is in the range of 1-3
{ // if the number is not in the range asks for it to be re enterd
printf("\n Invalid number of stops please re enter: ");
scanf("%5d",&numstops);
}
if(numstops==0) // if the number of stops is equal to 0
{
printf("\n From %s To %s is %d miles",pos[0],pos[1],dist[point[0]][point[1]]);
printf("\n Total distance : %d miles", dist[point[0]][point[0]]+dist[point[0]][point[1]]); // Adds the 2 points togteher to work out the distance
printf("\n\n\n");
}
if(numstops>0) // if the number of stops is greater than 0
{
for(i=0;i<numstops;i++) //loops round depeneding on how many stops was enterd
{
if(wrong !=1)// if wrong is 0 it will out put the following
{
printf("\n Please enter the name for Stop %-1d: ",i+1);
}
scanf("%16s",stopname[i]);
wrong=0;
size_t x;
flag =0; // sets flag to 0 so place is invalid until found
for(x = 0; x < sizeof(place); x ++)
{
if(strcmp(place[x+1], stopname[i])==0)
{
stops[i] = x; // set stops at position i is set to the value of x
flag=1; //sets flag as 1 because its a valid place
}
}
if(flag==0) // place not found
{
printf("\n Invalid place name please re enter: ");
i--; // decrements i by 1 sooo it will loop round again
wrong=1; // sets wrong to 1 so the ask for start or finsh point is not asked for again
}
}
//will print out the distances depending on how many stops was enterd
if(numstops==1)
{
printf("\n Starting from %s To %s is %d miles",pos[0],stopname[0],dist[point[0]][stops[0]]);
printf("\n From %s To %s is %d miles",stopname[0],pos[1],dist[point[1]][stops[0]]);
printf("\n Total Distance : %d",dist[point[0]][stops[0]]+dist[point[1]][stops[0]]);
printf("\n\n\n");
}
else if(numstops==2)
{
printf("\n Starting from %s To %s is %d miles",pos[0],stopname[0],dist[point[0]][stops[0]]);
printf("\n From %s To %s is %d miles",stopname[0],stopname[1],dist[stops[0]][stops[1]]);
printf("\n From %s To %s is %d miles",stopname[1],pos[1],dist[point[1]][stops[1]]);
printf("\n Total Distance : %d",dist[point[0]][stops[0]]+dist[stops[0]][stops[1]]+dist[point[1]][stops[1]]);
printf("\n\n\n");
}
else if(numstops==3)
{
printf("\n Starting from %s To %s is %d miles",pos[0],stopname[0],dist[point[0]][stops[0]]);
printf("\n From %s To %s is %d miles",stopname[0],stopname[1],dist[stops[0]][stops[1]]);
printf("\n From %s To %s is %d miles",stopname[1],stopname[2],dist[stops[1]][stops[2]]);
printf("\n From %s To %s is %d miles",stopname[2],pos[1],dist[point[1]][stops[2]]);
printf("\n Total Distance : %d",dist[point[0]][stops[0]]+dist[stops[0]][stops[1]]+dist[stops[1]][stops[2]]+dist[point[1]][stops[2]]);
printf("\n\n\n");
}
}
break;
case 3:
for(i=0;i<2;i++) // loops round twice allowing the input of 2 points
{
if(wrong!=1) // if wrong is 0 it will out put the following
{
if(i==0){printf("\n Please enter your Start point: ");} // input first point
if(i==1){printf("\n Please enter your Finishing point: ");} // input first point
}
wrong=0; // set wrong to 0
scanf("%16s", pos[i]);
size_t x;
flag = 0; // sets flag to 0 so place is invalid until found
for(x = 0; x < sizeof(place); x ++)
{
if(strcmp(place[x+1], pos[i])==0)
{
// place found
point[i] = x; // point at position i is set to the value of x
flag=1; //sets flag as 1 because its a valid place
}
}
if(flag==0) // place not found
{
printf("\n Invalid place name please re enter: ");
i--; // decrements i by 1 sooo it will loop round again
wrong=1; // sets wrong to 1 so the ask for start or finsh point is not asked for again
}
}
printf("\n From %s To %s is %d miles",pos[0],pos[1],dist[point[0]][point[1]]); //prints out the distance
if(dist[point[0]][point[0]]+dist[point[0]][point[1]] <=100) //if the distance is less than 100 set price to 0.4
{
price = 0.4;
printf("\n Your Journey is Less than 100 miles, Price per mile = %g",price);
}
else //if the distance is greater than 100 set price to 0.3
{
price = 0.3;
printf("\n Your Journey is Greater than 100 miles, Price per mile = %g",price);
}
printf("\n The price of your journey is : %5g", dist[point[0]][point[0]]+dist[point[0]][point[1]]*price); // Adds the 2 points togteher and multiplys by 0.4 to get the ppm
printf("\n\n\n");
break;
case 4: printf("\n Thankyou and goodbye");
exit(0);
break;
}
}
}
int menu(void) // menu funcion
{
int option;
printf("\n ============================================");
printf("\n M E N U ");
printf("\n ================++++++++++++================");
printf("\n 1. Display a complete mileage place ");
printf("\n 2. Calculate the distance of your journey ");
printf("\n 3. Calculate the cost of your journey ");
printf("\n 4. Exit ");
printf("\n --------------------------------------------");
printf("\n\n Please input your choice from the menu: ");
scanf("%d",&option);
while(option<1 || option>4) // validates that option is in the range of 1-4
{
printf("\n Invalid menu input please re enter: ");
scanf("%d",&option);
}
printf("\n\n");
return option;
}
void read(char place[11][11], int dist[10][10]) // read function
{
//variables
int i, j;
char filename[21], p1, p2;
FILE *in_file;
printf("\nEnter the name of the input file, name must be 20 charecters or less: ");
scanf("%s", &filename);
in_file = fopen(filename,"r"); // opens filename with read permission
while(in_file == NULL) // if the file cannont be found it will keep asking for one to be input
{
printf("\nCannot find file %s please re enter: ", &filename);
scanf("%s", &filename);
in_file = fopen(filename,"r");
}
if (in_file != NULL) //file is found
{
for(i=0;i<11;i++)
{
fscanf(in_file, "%s ", &place[i]); // reads in 11 place names
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
fscanf(in_file, "%d ", &dist[i][j]); // reads in 100 distaces
}
}
printf(" %s Opened Successfully", &filename); // confirms on screen that the file was opened successfully
printf("\n\n\n");
}
fclose(in_file); // closes the file
}
void display(char place[11][11], int dist[10][10])
{
int row, col;
printf("\n------------------------------------<<]]+++|||||MILEAGE CHART|||||+++[[>>-------------------------------------------\n\n");
for (row=0; row<11;row++)
{
printf("%-11s",place[row]); // outputs first row of place names
}
printf("\n");
for (row=0; row<10;row++)
{
printf("%-11s",place[row+1]);
for (col=0;col<10;col++)
printf("%-11d", dist[row][col]);
printf("\n");
}
printf("\n--------------------------------------------------------------------------------------------------------------------\n\n");
}
and well i tryed to comiple it using " cc -o name name.c" and well this is what i got :
http://i57.photobucket.com/albums/g2...OOOOMMMGGG.jpg
anyone know how i can fix this