Compilation problem

Status
Not open for further replies.
Hi everyone,

I've been trying to compile a short porgram in C that uses the sprintf() funcion
but
I get the following compilation error:

/user/bin/sh: -c:Line1: syntax error near unexpected token 'fi'

Any suggestions as to fixing this error?
 
:wave: Welcome to Techspot :wave:

Not that I'm a c/c++ programmer or anything, but given that it's a syntax related error, might it be useful to post your code? (as a txt attachment if there's a lot of it)
 
Hi Spike,
Thanks for the quick reply
this is the code:

#include <cstdio.h>
void printNumber(int number)
{
byte string[10];


sprintf( string, "%d", number );
printString(string);
}

void printString(char txt[])
{
byte i;

for(i=0;i<strlen(txt);i++)
{
USART_Transmit(txt);
}
}
 
That ones a bit beyond my VERY VERY basic C knowledge. There are a few people here that can really code in C though, and hopefully one of those might be able to help you.

Edit:

sprintf( string, "%d", number );
Are those spaces inside each side of the brackets supposed to be there?
 
Hi everyone,

Does anybody know how to get a hold of the <cstdio.h> and <stdlib.h> header files
and add them to the Command Prompt compiler to compile a C program?
 
cibiieph said:
/user/bin/sh: -c:Line1: syntax error near unexpected token 'fi'
As you see, this error is reported by the sh shell. You are running some shell script and there is an error in that script. Nothing to do with C++ or compilers.

Does anybody know how to get a hold of the <cstdio.h> and <stdlib.h> header files
and add them to the Command Prompt compiler to compile a C program?
These headers should come with your C compiler. The exact syntax of specifying include paths depends on the compiler you use. For gcc you'd add "-I /some/additional/include/files/path" to the command line. Mind you, these standard headers should exist in standard locations and your compiler should find these all by itself. If your compiler fails to find these for some reason, try them without the .h suffix - the new C standard headers are without .h and .hpp extensions.
 
Status
Not open for further replies.
Back