Looking into learning C. As I understand it when I say #include <stdio.h> it grabs stdio.h from the default location…usually a directory inside your working directory called include. How do I actually get the file stdio.h? Do I need to download a bunch of .h files and move them from project to project inside the include directory? I did the following in a test.c file. I then ran make test and it outputted a binary. When I ran ./test I did not see hello print onto my screen. I thought I wasn’t seeing output maybe because it doesn’t find the stdio.h library. But then again if I remove the greater than or less than signs in stdio the compiler gives me an error. Any ideas?
I’m on a Mac running this from the command line. I am using: GNU Make 3.81. This program built for i386-apple-darwin10.0
#include <stdio.h>
main()
{
printf("hello");
}
Edit: I have updated my code to include a datatype for the main function and to return 0. I still get the same result…compiles without error and when I run the file ./test it doesn’t print anything on screen.
#include <stdio.h>
int main()
{
printf("hello");
return 0;
}
Update:
If I add a \n inside of the printf it works! so this will work:
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}
Your code should have preferably
or
If you want to know where does the standard header file
<stdio.h>comes from, you could run your compiler with appropriate flags. If it isgcc, try compiling withPedantically, a standard header file is even not required to exist as a file; the standard permits an implementation which would process the
#include <stdio.h>without accessing the file system (but e.g. by retrieving internal resources inside the compiler, or from a database…). Few compilers behave that way, most really access something in the file system.