954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

dont use printf or puts functions

hi


i have problem i have to devolpe a program ,that can't use a printf ,but i have to display a string.

is this works


int a = printf("How is this\n");
main()
{
int b;
}

This will work in C++ wht abt c?

AND one more HOW sizeof()
implemented in C means Sourrce code ?

satyanarayanam
Newbie Poster
4 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

>This will work in C++ wht abt c?
No, it won't work in either because you can't call a function at global scope. It also fails to meet the requirements because you try to use printf. :icon_rolleyes:

>HOW sizeof() implemented in C means Sourrce code?
You can't do it portably. That's why C has a sizeof operator.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Can you use putchar() and display each character one at a time?

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

cin and cout?

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

you cant call a function outside main(),

in c++ you can use cout to output data, that requires iostream.h so if you feel you want to use that in c, copy the header file to c's directory.

when you're thinking you can use string functions, you're wrong, string functions require printf or puts to output data..actually, we always use that functions in c.

now, how will you output data without using those functions?

well, you must create one, you can edit or create header files, ..
by that, you create a function that outputs data, and name it your way...

In c++, just use cout..

goodluck!!

iTaChi
Newbie Poster
21 posts since Mar 2007
Reputation Points: 29
Solved Threads: 2
 
>This will work in C++ wht abt c? No, it won't work in either because you can't call a function at global scope....


calling a function at global scope is certainly possible in C++. dynamic initialization of statics at global scope is supported; here caling printf to initialize a global integer is no different from calling the constructor to initialize std::cout.

if you cannot use formatted output functions like printf, fprintf etc., an fwrite (unformatted output) is a possibility. fwrite returns a size_t, so you can still use it for dynamic initialization of a global int.

vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You