Getting started with C on the Raspberry Pi

Hi all,

This is a really simple question, but I can't seem to find an answer online. I'm just starting to learn C in order to programme my Raspberry Pi which will lead to my first robot. I've done a fair bit of programming in VB before, but C is completely new to me.

I'm literally starting at the beginning with the 'Hello World' text and my code is:

 

#include <stdio.h>

int main()

{

printf("Hello world!"\n);

return 0;

}

However, every time I try to run this from Geany, I get the following error:
./geany_run_script.sh: 5: ./geany_run_script.sh: ./First: not found
------------------
(program exited with code: 127)
Any help or guidance on how to solve this would really be appreciated.
Regards,
Henry.

I just copied and pasted your code

in to geany on my system. There was an issue with your print statement as you posted it. “Hello World!”\n does not work. \n is a character, and, as such it needs to be inside the quotes.

#include <stdio.h>

int main() {
  printf(“Hello world!\n”);
  return 0;
}

compiled and ran fine for me.

Make sure the file is set as

Make sure the file is set as an executable. Use the ll command to see if it is. If it isn’t, use “sudo chmod +x filename”. Also, how are you trying to run the program (what are you typing in the command prompt?)

Make sure the file is set as

I’m not sure why a .sh file is involved.

Thank you for all the quick

Thank you for all the quick replies, it’s really appreciated. I couldn’t seem to fix the problem even after I corrected the \n, so I’m going to reinstall Geany and see if that helps. Will keep you posted, fingers crossed I can get it working!

Turns out I was being very

Turns out I was being very silly indeed - I’d forgotten to add ‘.c’ to the file name! How embarrassing. Thank you for all the help, it’s really appreciated.