Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C -- Print To Screen Without #include <stdio.h>? [closed]

Tags:

c

Is there a way to have a C source file print to the screen without including <stdio.h>?

Here's my situation: I was asked to programatically handle 1000 C source files that will each implements several numerical functions in C (these functions are supposed to work on data that is in memory, eithout any I/O). The origin of these source files in unclear, and hence, I'd like to make sure there will be no harm to my machine when I compile & run these source files.

Is there a way to find out if a C source file is potentially harmful? I thought of asking the developers to avoid any #include statements whatsoever, but I do need just printf -- as I'd like them to include an output of their calculations within main().

Any ideas?

like image 382
user3262424 Avatar asked Jul 24 '11 21:07

user3262424


People also ask

How will you print on the screen in C?

8) The statement used for printing \n on the screen is:printf("n\");

How can I print my name without printf?

How do you print your name in C language without using any printing function like printf and all? int main() { write(1, "Hello World", strlen("Hello World")); return 0; } This could be one way of printing without using printf, sprintf, and all related functions.

Why does C use printf and not print?

The most basic printing functions would be puts and putchar which print a string and char respectively. f is for formatted. printf (unlike puts or putchar ) prints formatted output, hence printf. For example it can print an int in hexadecimal, or a float rounded to three decimal places, or a string left padded.


2 Answers

Sure, add the prototype for printf at the top of your source file, as long as you're linking to the CRT libraries you can use the function without including stdio.h

printf prototype

int printf ( const char * format, ... );
like image 121
Praetorian Avatar answered Oct 10 '22 18:10

Praetorian


There are, though they are probably a bit larger than the scope of the format of SO. In essence you leverage assembler calls in C. The blog KSplice touches on the subject ( with code and examples ) here.

like image 38
zellio Avatar answered Oct 10 '22 18:10

zellio