Syntax Adjustment in C code block

This is a discussion on Syntax Adjustment in C code block within the C Programming forums, part of the General Programming Boards category; I'm supposed to program an LCD screen in MC9S12E128 that outputs the a couple of names on it. The name ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    Syntax Adjustment in C code block

    I'm supposed to program an LCD screen in MC9S12E128 that outputs the a couple of names on it. The name changes each time the push buttons are pushed. This needs to be done with C language. I wrote this code so far but it seems to be wrong..

    PHP Code:
    #include <hidef.h> /* common defines and macros */
    #include <mc9s12e128.h> /* derivative information */
    #include < stdio.h>
    #pragma LINK_INFO DERIVATIVE "SampleS12"

    void initPort(void);
    int main () {
    PORTB 0x00;
    PORTA 0x00;
    PORTE 0X00;
    DDRA 0XFF;
    DDRE 0xFF;
    }

    void main (){
    char name1[8],name2[8],name3[8],name4[8];
    int input

    EnableInterrupts;
    for(;;) { 

    PORTE=0x01 

    DDRE DDRA ;
    }
    char *name1 [8] = "Name1"
    char *name2 [8] = "Name2" ;
    char *name3 [8] = "Name3";
    char *name4 [8] = "Name4" ;

    switch ( 
    input ) {
    case 
    1/* Note the colon, not a semicolon */
    PORTAname1 

    break;
    case 
    2

    PORTA name2 

    break;
    case 
    3:
    PORTA name3 

    break;

    default: 
    PORTA name4
    break;
    }
    getchar();
    }
    }
    }

    The debugger tells me that Return is Expected n stuff, any idea what could be wrong with my code? Would really appreciate your help..
    Thanks!

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Code:
    int main () {
    PORTB = 0x00;
    PORTA = 0x00;
    PORTE = 0X00;
    DDRA = 0XFF;
    DDRE = 0xFF;
    }
    Don't know as far as embedded devices and what have you go. But this is still C, you must return some integer. Usually returning 0 from main() means "no error".
    You also can't have another function of the same name, there is no overloading/overriding in vanilla C. You have 2 main()s pick one. Note that void main() is "wrong" -- see the FAQ.

    Just remember to be careful, with some compilers using void main() can cause the computer to physically catch fire.
    Last edited by zacs7; 11-26-2008 at 03:41 AM.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    Just remember to be careful, with some compilers using void main() can cause the computer to physically catch fire.
    Are you serious? XD
    This is my first time working with C really, so im as clueless as hell. Got to fix the return problem, thanks a million for that Zac. Also change void main() to void body().. One curly bracket error to be fixed and it should all work. Here is how the code looks now..

    PHP Code:
    #include <hidef.h>      /* common defines and macros */
    #include <mc9s12e128.h>     /* derivative information */
    #include < stdio.h>
    #pragma LINK_INFO DERIVATIVE "SampleS12"


    void initPort(void);
    int main () {
      
      
     
      
    PORTB 0x00;
      
    PORTA 0x00;
      
    PORTE 0X00;
      
    DDRA 0XFF;
      
    DDRE 0xFF;
      return 
    0;
    }

            
    void body (){
            
    char name1[8],name2[8],name3[8],name4[8];
            
    int input
                    
      
    EnableInterrupts;
      
       for(;;) { 
                
         
    PORTE=0x01 
         
    DDRE DDRA ;
      }
      
    char *name1 [8] = "Name1"
      
    char *name2 [8] = "Name2"  ;
      
    char *name3 [8] = "Name3";
      
    char *name4 [8] = "name4" ;
     
       switch ( 
    input ) {
            case 
    1:            /* Note the colon, not a semicolon */
               
    PORTAname1 
          
                
    break;
            case 
    2:          
                      
             
    PORTA name2 
                
                
    break;
            case 
    3:
           
    PORTA name3 
             
                
    break;
           
            default:            
                
    PORTA name4
                
    break;
        }
        
    getchar();
    }
    }
    }


  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    Okay, this has been getting on my nerves lol.. It keeps on saying ' } ' missing, one the line marked below..

    PHP Code:
    #include <hidef.h>      /* common defines and macros */
    #include <mc9s12e128.h>     /* derivative information */
    #include < stdio.h>
    #pragma LINK_INFO DERIVATIVE "SampleS12"


    void initPort(void);
    int main () {
      
      
     
      
    PORTB 0x00;
      
    PORTA 0x00;
      
    PORTE 0X00;
      
    DDRA 0XFF;
      
    DDRE 0xFF;
      return 
    0;
    }

            
    void body (){
            
    char name1[8],name2[8],name3[8],name4[8];
            
    int input
                    
      
    EnableInterrupts;
      
       for(;;) { 
                
         
    PORTE=0x01 
         
    DDRE DDRA ;
      }
      
    char *name1 [8] = "Name1";               // Error indication came here
      
    char *name2 [8] = "Name2"  ;
      
    char *name3 [8] = "Name3";
      
    char *name4 [8] = "Name4" ;
     
       switch ( 
    input ) {
            case 
    1:           
               
    PORTAname1 
          
                
    break;
            case 
    2:          
                      
             
    PORTA name2 
                
                
    break;
            case 
    3:
           
    PORTA name3 
             
                
    break;
           
            default:            
                
    PORTA name4
                
    break;
        }
        
    getchar();
    }
    }
    }

    Where is it missing?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Priobably because you are declaring variables after you have started with the code - the actual error message is a bit confusing, but I think it's simply a compiler gets confused sort of situation.

    Also, your code never calls "body".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,767
    You might want to properly indent your code:
    Code:
    #include <hidef.h>      /* common defines and macros */
    #include <mc9s12e128.h>     /* derivative information */
    #include <stdio.h>
    #pragma LINK_INFO DERIVATIVE "SampleS12"
    
    void initPort(void);
    
    int main() {
        PORTB = 0x00;
        PORTA = 0x00;
        PORTE = 0X00;
        DDRA = 0XFF;
        DDRE = 0xFF;
        return 0;
    }
    
    void body() {
        char name1[8],name2[8],name3[8],name4[8];
        int input;
    
        EnableInterrupts;
    
        for(;;) {
            PORTE=0x01 ;
            DDRE = DDRA ;
        }
    
        char *name1 [8] = "Name1";               // Error indication came here
        char *name2 [8] = "Name2"  ;
        char *name3 [8] = "Name3";
        char *name4 [8] = "Name4" ;
    
        switch ( input ) {
        case 1:
            PORTA : name1
            break;
        case 2:
            PORTA : name2
            break;
        case 3:
            PORTA ; name3
            break;
        default:
            PORTA : name4
            break;
        }
        getchar();
    }
    }
    }
    }
    At a glance, you have three extra closing braces, and in your switch you probably want to assign to PORTA instead of using it as a label. The current error you have might be because you declared some variables (name1, name2, name3 and name4) in the middle of a block, and that is not allowed prior to the 1999 edition of the C standard.

    Oh, and you probably want to call body() from main().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 10:24 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. What is the syntax for a #define for several lines of code?
    By Jonas_Valleskog in forum C Programming
    Replies: 7
    Last Post: 01-31-2003, 11:22 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

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