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

Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list?

1 Answers   Oracle,


what is pointer?

4 Answers  


What are the types of arrays in c?

0 Answers  


What will be your course of action for a push operation?

0 Answers  


What is volatile c?

0 Answers  






in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

0 Answers  


declare afunction pointer to int printf(char *)?

1 Answers   HCL,


Write a program for finding factorial of a number.

0 Answers   Tech Mahindra,


Give me basis knowledge of c , c++...

5 Answers  


What is sorting in c plus plus?

0 Answers  


Is c object oriented?

0 Answers  


Q-1: Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college.

8 Answers  


Categories