Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run c program - stdio.h where do i get it?

Tags:

c

unix

makefile

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;
    }
like image 979
user983223 Avatar asked Jun 17 '26 05:06

user983223


1 Answers

Your code should have preferably

 printf("hello\n");

or

 puts("hello");

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 is gcc, try compiling with

gcc -H -v -Wall hello.c -o hello

Pedantically, 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.

like image 144
Basile Starynkevitch Avatar answered Jun 19 '26 20:06

Basile Starynkevitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!