Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 / vinay tiwari

this can be achieved by file handling

#include<stdio.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("file.c","r");
ch=getc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=getc(fp);
}
getch();
}

Is This Answer Correct ?    63 Yes 33 No

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

Answer / manish

#include<stdio.h>

char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";
main()
{
printf(s,34,s,34);
}

Is This Answer Correct ?    25 Yes 15 No

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

Answer / joyab

#include <stdio.h>

int main()
{
char a[] = "int main(){char a[] = %c%s%c; char b = '%c'; printf(a,b,a,b,b);}";
char b = '"';

printf(a,b,a,b,b);
}

Is This Answer Correct ?    9 Yes 9 No

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

Answer / abhishek

#include <stdio.h>

static char prog[] = "#include <stdio.h>%c%cstatic char prog[] = %c%s%c;%c%cint main(void)%c{%c printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";

int main(void)
{
printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);
return 0;
}

Is This Answer Correct ?    6 Yes 6 No

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

Answer / swamy

#include<stdio.h>
#include<conio.h>
int main()
{
FILE * fp = NULL;
char c = '\0';
fp = fopen(__FILE__,"r");
while(!feof(fp))
{
c = fgetc(fp);
printf("%c",c);
}
getch();
}

Is This Answer Correct ?    4 Yes 5 No

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

Answer / hillel

#include<fstream>
void main()
{
std::ifstream is(__FILE__);

while(!is.eof())
printf("%c", is.get());

is.close();
}

Is This Answer Correct ?    5 Yes 7 No

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

Answer / yang

main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}

copied from somewhere, but it works

Is This Answer Correct ?    17 Yes 20 No

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

Answer / neenu jacob

#include <stdio.h>

main()
{
int pid,ppid;
int q=getpid();
int gid,egid,uid,euid;
int f=fork();
if (f==0)
{
printf("hai\n%d\n%d\n%d",getuid(),geteuid());

}
else
{
pid=getpid();
ppid=getppid();
printf("%d\n%d\n%d\n%d",pid,ppid,q,f);
}
system("cat /home/mec/lab1.c");
}

Is This Answer Correct ?    0 Yes 3 No

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

Answer / vikraman85

This can be achieved by file handling,
If r is the name of this file;The following codewil print
this prg.

#include<stdio.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("file.c","r");
ch=getc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=getc(fp);
}
getch();
}

Is This Answer Correct ?    19 Yes 23 No

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

Answer / mobashyr

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


int main()
{
FILE *fin;
char c;
fin=fopen("prntsrccode.c","r");
if(fin==NULL)
{
printf("Error Opening file in read mode");
exit(1);
}
do
{
c=fgetc(fin);
fputchar(c);
}while(c!=EOF);

fclose(fin);

getch();
return 0;
}

Is This Answer Correct ?    3 Yes 7 No

Post New Answer

More C Interview Questions

a number is perfect if it is equal to the sum of its proper divisor.. 6 is perfect number coz its proper divisors are 1,2 and three.. and 1+2+3=6... a number is deficient if the sum of its proper divisor is less than the number.. sample: 8 is deficient, coz its proper divisors are 1,2 and 4, and 1+2+4=7. abundant number, if the sum of its proper divisor is greater than the number.. sample..12 is abundant coz 1+2+3+4+6=16 which is geater than 12. now write a program that prompts the user for a number, then determines whether the number is perfect,deficient and abundant..

1 Answers  


what is diognisis?

1 Answers  


plz let me know how to become a telecom protocol tester. thank you.

0 Answers  


What is the purpose of main() function?

0 Answers  


while initialization of array why we use a[][2] why not a[2][]...?

0 Answers   Aptech,


What is the difference between test design and test case design?

0 Answers  


Explain what does the format %10.2 mean when included in a printf statement?

0 Answers  


What is the sizeof () a pointer?

0 Answers  


Why c language is called c?

0 Answers  


implement general tree using link list

1 Answers   Wipro,


#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }

1 Answers  


what is the use of macro program

1 Answers   TCS,


Categories