Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use scanf() without including stdio.h

Tags:

c

Is there any possible methods to write a C program without including stdio.h as a header file. It was suggested that it can be implemented by declaring extern int scanf(char* format, ...);

#include <stdio.h> //I want this same code to work without including this line

int main ()
{
  char str [80];
  scanf ("%s",str);  
  return 0;
}
like image 872
Niko Avatar asked Aug 13 '13 10:08

Niko


People also ask

Can we use printf without Stdio H?

The <stdio. h> header contains (directly or indirectly) certain prototypes, but the library has to be linked in separately. Since printf is usually in a library that is linked to programs by default, you usually don't have to do anything to use printf .

Can you code in C without Stdio H?

It just means you don't have a standard facility to do so and will need to call custom functions. To answer your question: you can do anything in C without stdio. It's all written in C anyway, you're just losing some common functionality implemented in any C standard library. Save this answer.

What is Stdio H is not included in C?

stdio. h is a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc. If we want to use printf or scanf function in our program, we should include the stdio. h header file in our source code.

Is scanf in Stdio H?

printf and scanf are two standard C programming language functions for input and output. Both are functions in the stdio library which means #include <stdio. h> is required at the top of your file. Function arguments: int scanf(const char * format, [var1], [var2],…)


1 Answers

You can declare the scanf function with:

extern int scanf(const char *format, ...);

The extern keyword is optional but I like to include it as a reminder of the fact that the function is defined elsewhere.

Your example would then look like:

extern int scanf(const char *format, ...);

int main ()
{
  char str [80];
  scanf ("%s",str);  
  return 0;
}
like image 182
Joni Avatar answered Sep 22 '22 01:09

Joni