a carrige-return character was encounterd; loads of errors helpp please :)

This is a discussion on a carrige-return character was encounterd; loads of errors helpp please :) within the C Programming forums, part of the General Programming Boards category; i have been making my program on dev c++ and well i have to have it running on the school ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    147

    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("&#37;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

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    And I'm supposed to be able to read that?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Looks like that compiler is just being stupid. Ignore the warnings. A "carriage return" is a perfectly valid whitespace character.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    147
    yea i ignored the silly compiler and it seems to run fyne oh and sorry for the poor layout and probley spelling

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    In all likelihood, the source file was written on a Windows machine and thus has DOS-style line endings, but compiled on a UNIX or Linux machine. From a Linux compiler's point of view, carriage returns are whitespace, but not line endings. It is a rather silly warning, but I guess it's trying to tell you that you may have strange "newline" characters in your file that other tools might not handle properly.

    [edit] Dave beat me. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21