Someone could please tell me why this little piece of code generate ***** syntax error near 'char' #include <stdio.h> /* standard I/O .h-file */ #include <XC161.h> /* special function register XC161 */ #include <math.h> /****************/ /* main program */ /****************/ void main (void) { /* execution starts here */ /* initialize the serial interface */ #ifndef Monitor /* do not initialize if you use Monitor-166 */ P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */ DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */ DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */ ASC0_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ ASC0_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ ASC0_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */ ASC0_CON = 0x8011; /* SET SERIAL MODE */ ALTSEL0P3 |= 0x0C00; /* Configure port pins for serial interface 0 */ #endif char nome[10]; int i; int j=0; while (1) { i=-1; nome[0]='a'; /* An embedded program does not stop and */ do { i++; nome[i]=getchar(); // printf("%c",nome[i]); } while (nome[i]!=0x00A); printf("Ciao, "); for (j=0;j<=i;j++) printf("%c",nome[j]); } /* loop. You may wish to put in your own */ } and instead this works : #include <stdio.h> /* standard I/O .h-file */ #include <XC161.h> /* special function register XC161 */ #include <math.h> /****************/ /* main program */ /****************/ void main (void) { /* execution starts here */ /* initialize the serial interface */ #ifndef Monitor /* do not initialize if you use Monitor-166 */ P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */ DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */ DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */ ASC0_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ ASC0_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ ASC0_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */ ASC0_CON = 0x8011; /* SET SERIAL MODE */ ALTSEL0P3 |= 0x0C00; /* Configure port pins for serial interface 0 */ #endif while (1) { char nome[10]; int i; int j=0; i=-1; nome[0]='a'; /* An embedded program does not stop and */ do { i++; nome[i]=getchar(); // printf("%c",nome[i]); } while (nome[i]!=0x00A); printf("Ciao, "); for (j=0;j<=i;j++) printf("%c",nome[j]); } /* loop. You may wish to put in your own */ } /* for both of them, i've choose the small memory model, and near 6 for data threshold. Pleas help me, or i'll go crazy!
"No he doesn't - it isn't a preprocessor problem, it is a 'C' syntax problem." Oh yes - so it is. But even then, reading the preprocessor listing might help, as all the preprocessor directives will be stripped out. Then he should find it obvious that he has variable definitions after executable code in a block - which is not allowed. That's why the message says, "syntax error near 'char'" - because 'char' is not syntactically allowed to appear in a definition like that after executable code! Nothing strange at all!