473,406 Members | 2,816 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,406 software developers and data experts.

how does this program work?

this program print its own source code without opening the source file.
would some one please explain me how does it work ,and what what process takes place in this program????

#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%c%cprintf(program, 10, 34, program, 34, 10, 10, 10, 9, 10, 9, 10, 10,10);%c%creturn 0;%c}%c";
int main()
{
printf(program, 10, 34, program, 34, 10, 10, 10, 9, 10, 9, 10, 10,10);
return 0;
}
Jan 15 '07 #1
6 2589
Ganon11
3,652 Expert 2GB
This program is simply outputting the code. It will only output this code, so if you add any statements to it, it will not print the exact code anymore. All that is being used is simple output statements. It just happens to print the strings that you typed in to make source code.
Jan 15 '07 #2
This program is simply outputting the code. It will only output this code, so if you add any statements to it, it will not print the exact code anymore. All that is being used is simple output statements. It just happens to print the strings that you typed in to make source code.
well i knew that it print its own code But what i want to know is :
is it a recursive fuction in the first line and what is its ending condition(order).
becuase we see while with no condition: while( );
i want to explain all the things has writen in the code please, PLEASE.....
Jan 15 '07 #3
Ganon11
3,652 Expert 2GB
There is no recursive function, or loop, or anything. The program makes a character array that represents the code, and then prints that character array. There's nothing complicated here.
Jan 15 '07 #4
r035198x
13,262 8TB
well i knew that it print its own code But what i want to know is :
is it a recursive fuction in the first line and what is its ending condition(order).
becuase we see while with no condition: while( );
i want to explain all the things has writen in the code please, PLEASE.....
I don't see any while in this program. What do you mean by "we see a while with no condition"?
Jan 15 '07 #5
I don't see any while in this program. What do you mean by "we see a while with no condition"?
oops!
it seems i had a BIG mistake!
but i still want some explain about the second line (and what does variable *p do).
and also why function printf(""); in the main function doesn't have any argument??????
Jan 15 '07 #6
r035198x
13,262 8TB
oops!
it seems i had a BIG mistake!
but i still want some explain about the second line (and what does variable *p do).
and also why function printf(""); in the main function doesn't have any argument??????
Maybe you should re-read the tutorials again. Make sure you understand what an argument is and what *p means etc
Jan 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
22
by: Robert Bralic | last post by:
CAN anybody tell me any address where I can download some small(1000-2000) lines C++ proghram source. Or send me ,a small(1000-2000) lines C++ program source that I can compille with gpp under...
15
by: Generic Usenet Account | last post by:
While I have a very good feel for how inlining works, I fail to see how in the world inlining can work if the inlined function is not described "in place" in a header file, but rather defined in a...
22
by: Ryan M | last post by:
I've been programming for a while, but most of my experience is on unix. How do C compilers work on operating systems that weren't written in C? And that have no libc? Compiling C on unix seems...
24
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
126
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.