Run c program - stdio.h, where can I get it?

Looking closely at C. As I understand it, when I say #include <stdio.h>

it grabs stdio.h from the default location ... usually there is a directory inside your working directory called include. How can I get the stdio.h file? 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 the test.c. file Then I ran a make test and dumped the binary. When I was running. / test, I didn't see my welcome screen. I thought I couldn't see the output because it doesn't find the stdio.h library. But then again, if I remove more or less characters in stdio, the compiler gives me an error. Any ideas?

I am working on Mac from the command line. I am using: GNU Make 3.81. This program is built for i386-apple-darwin10.0

#include <stdio.h>

main()
{
  printf("hello");
}

      

Edit: I updated my code to include the datatype for the main function and return 0. I still get the same result ... compiles without error and when I run the file. / test, it doesn't print anything to the screen.

#include <stdio.h>

int main()
{
  printf("hello");
  return 0;
}

      

Update: If I add \ n inside printf it works! so this will work:

#include <stdio.h>

    int main()
    {
      printf("hello\n");
      return 0;
    }

      

+3


source to share


4 answers


Your code should preferably have

 printf("hello\n");

      

or

 puts("hello");

      



If you want to know where the standard header file comes from <stdio.h>

, you can run your compiler with the appropriate flags. If so gcc

, try compiling with

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

      

Pedantically, a standard header file is not even required to exist as a file; the standard allows an implementation that would handle #include <stdio.h>

without access to the filesystem (but, for example, by fetching internal resources inside the compiler or from the database ...). Few compilers behave this way; most actually access something in the filesystem.

+1


source


If you didn't have the file, you will get a compilation error.

I am assuming that the text was printed, but the console was closed before you could see it.



It also main

returns int

and you must return 0;

succeed.

+1


source


#include <header.h>

, with angle brackets, search in standard system locations known to the compiler - not in your project subdirectories. On Unix systems (including your Mac, I believe) is stdio.h

usually found in / usr / include. If you are using #include "header.h"

, search subdirectories first and then the same locations as with <header.h>

.

But you don't need to search or copy the title to run your program. It is read at compile time, so yours. / test doesn't need it at all. Your program looks like it worked. Is it possible that you just typed "test" and not "./test" and got the system command "test"? (Suggestion: Don't call your programs "test".)

0


source


Just going to leave it here: STILL! in 2018, in December ... Linux Mint 18.3 has no support for C development.

innocent / # cc TheSorts.c

TheSorts.c: 1:19: fatal error: stdio.h: such compilation of the file or directory has not completed.

innocent / # gcc TheSorts.c

TheSorts.c: 1:19: fatal error: stdio.h: such compilation of the file or directory has not completed.

innocent / # apt show libc6

(
Shorthand ) :: Package: libc6
Version: 2.23-0ubuntu10
Priority: Required
Section: libs
Source: glibc
Origin: Ubuntu
Installed Size: 11.2 MB
Depends on: libgcc1
Homepage: http://www.gnu.org/software /libc/libc.html
Description: GNU C Library: Shared Libraries
Contains standard libraries that are used by almost all programs on the
system. This package includes generic versions of the C standard library
and the standard math library, among many others.

innocent / # apt-get install libc6-dev libc-dev
So the magic ... and after a minute they are all installed on the computer and then everything works as it should.

Not all distributions bundle all C support libraries in every ISO. Hunh.

Unknown / # gcc TheSorts.c

low-intensity /#./a.out

20 18 17 16 .........

0


source







All Articles