write a C program to print the program itself ?!

Answers were Sorted based on User's Feedback



write a C program to print the program itself ?!..

Answer / vara

Most simplest ....

char *p="char *p=%s int main(){ printf(p,p);getchar();}";int
main(){ printf(p,p);getchar();}

Is This Answer Correct ?    0 Yes 4 No

write a C program to print the program itself ?!..

Answer / moumita chatterjee

#include<stdio.h>
#include<conio.h>
int main()
{
FILE *fp;
char c;
fp=fopen("G:\\selfpro.c","r");
if(fp==NULL)
{
puts("File can open");
exit(1);
}
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
else
printf("%c",c);
}
getch();
return 0;
}

Is This Answer Correct ?    0 Yes 4 No

write a C program to print the program itself ?!..

Answer / prasanna kumar s

#include<stdio.h>
#include<conio.h>

void main()
{

clrscr();
printf("welcome 2 c language");
getch();

}

Is This Answer Correct ?    0 Yes 5 No

write a C program to print the program itself ?!..

Answer / jaroosh

The most simple possible program printing itself on windows :
main()
{
char path[255];
sprintf(path,"cmd.exe /c type \"%s\"",__FILE__);
system(path);
}

on Unix you just use "cat" instead of "type" and necessary
fun to call bash command from c program.

Is This Answer Correct ?    17 Yes 23 No

write a C program to print the program itself ?!..

Answer / sriram

#include<iostream.h>
#include<conio.hg>
int main()
{
clrscr();
printf(" \t hi this is sriram \t \n");
getch();
return 0;
}

Is This Answer Correct ?    4 Yes 93 No

write a C program to print the program itself ?!..

Answer / abiraj1030&yahoo.com

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hai");
getch();
}

Is This Answer Correct ?    10 Yes 112 No

Post New Answer

More C Interview Questions

main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(ā€œ%dā€,x); }

8 Answers   Vector,


write a programming in c language, 1 3 5 7 9 11

2 Answers   NIIT,


Why use int main instead of void main?

0 Answers  


how can you print&scan anything using just one character? :) HINT: printf,scanf similer

2 Answers  


Explain how can I prevent another program from modifying part of a file that I am modifying?

0 Answers  






What does volatile do?

0 Answers  


Why does everyone say not to use gets?

0 Answers  


If "AaBbCc" is passed to the char char x(*a) { a[0]?x(a+1):1; printf("%c",a[0]); return 1; } what will be the output?

6 Answers   Hughes,


What are the __date__ and __time__ preprocessor commands?

0 Answers  


how to find greatet of 10 numbers without using array?

4 Answers  


given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5)

6 Answers   amu, TCS,


code for copying two strings with out strcpy() function.

6 Answers  


Categories