473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Outputting a string to STDOUT with our libc functions

how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib
Aug 17 '08 #1
4 1891
On 2008-08-17, raashid bhatt <ra**********@gmail.comwrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}
Because that will work on Windows and only Windows.

puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.

--
Andrew Poelstra ap*******@wpsoftware.com
To email me, use the above email addresss with .com set to .net
Aug 17 '08 #2
raashid bhatt wrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib
This will tie your code to the Windows API while using puts will mean
that your program can run wherever a conforming ISO C implementation is
available, which is far more widespread than implementations of the
Windows API.

Aug 17 '08 #3
Andrew Poelstra <ap*******@supernova.homewrites:
[...]
puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.
Or C90 freestanding implementations; the distinction between
freestanding and hosted implementations isn't new in C99.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 18 '08 #4
On 17 Aug, 18:47, raashid bhatt <raashidbh...@gmail.comwrote:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
* * HANDLE handle;
* * handle = GetStdHandle(STD_OUTPUT_HANDLE);

* * WriteFile(handle, "hello world!", 12, NULL, NULL);
* * CloseHandle(handle);
* * return 0;

}

link /ENTRY:main program.obj kernel32.lib
Of course, printf can also do formatting - that's what the "f" stands
for.
Aug 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham Ashton | last post by:
Hi. I'm having trouble flushing sys.stdout. I've written a small example to illustrate my problem (see below). In short, I expect it to ping "received hello", sleep for 5 seconds and then print...
12
by: gc260262 | last post by:
Hi, I need functions that would return null terminated strings for me, for example: char *HTMLi(const char *string) This function receives a pointer to a null terminated string, and should...
4
by: xdevel | last post by:
Hi, if I want to read the string functions source code (i.e. strcpy, strtok etc.) where can I find them?
29
by: Andrea | last post by:
I want to write a program that: char * strplit(char* str1, char *str2, char * stroriginal,int split_point) that take stroriginal and split in the split_point element of the string the string...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
7
by: Pietro Cerutti | last post by:
Hi group, I just noticed that a malloc w/out relative free occurs in the standard C library (or at least, on my implementation of it). #include <stdio.h> int main(void) { printf("%s\n",...
3
by: grbgooglefan | last post by:
PythonC API function PyErr_Print( ) prints an error string onto stderr if PyErr_Occurred() is true. I don't want to print this to stderr because my Python+C code is running daemon mode & won't...
0
by: Christian Heimes | last post by:
Grant Edwards wrote: It's dangerous to mix streams and descriptors. Traditionally freopen() is used to redirect a standard stream to a file: ...
7
by: S James S Stapleton | last post by:
I want to debug a program, but I can't figure out what I'm doing wrong. I am screwing up a part of my libc (which I have access to the source for). If I compile my own copy of these functions, is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.