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;
}
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 .
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.
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.
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],…)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With