ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How do you write a program which produces its own source 
code as its output?
 Question Submitted By :: Swapna
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 1
//      PROGRAM which prints itself
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
void main()
 {
    char ch;
    clrscr();
    fstream fout;
    fout.open("itself.c",ios::in);
    if(!fout)
      {
	printf("\n cant open");
	exit(0);

      }
    while(ch!=EOF)
     {
      ch=fout.get();
      cout<<ch;
     }

    fout.close();

 }



//the file name is itself.c
 
Is This Answer Correct ?    2 Yes 3 No
Splurgeop
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 2
Can u write above program in C
 
Is This Answer Correct ?    0 Yes 2 No
Chandu
 
 
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 3
#include <stdio.h>
main()
 {
   FILE *fd;
   int c;

   fd= fopen("./file.c","r");
   while ( (c=fgetc(fd)) != EOF)
   {
     printf("%c", c);
   }
   
   fclose(fd);
 }
 
Is This Answer Correct ?    2 Yes 1 No
Ram
 
  Re: How do you write a program which produces its own source code as its output?
Answer
# 4
#include <stdio.h>

main()
{
  printf("%s\n", __FILE__);
  FILE* fp = fopen(__FILE__, "r");

  char buf[4096];
  while (!feof(fp))
  {
    fgets(buf, 4096, fp);
    printf("%s",buf);
  }

  fclose(fp);
}
 
Is This Answer Correct ?    1 Yes 1 No
Lijun Li
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
How to read a directory in a C program?  3
Program to Delete an element from a doubly linked list. Infosys4
Program to find the largest sum of contiguous integers in the array. O(n)  5
write a program to count the number the same (letter/character foreg: 's') in a given sentence.  1
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) Disney2
Finding a number which was log of base 2 NetApp1
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Microsoft4
plz send me all data structure related programs  2
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. Synergy2
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
How to return multiple values from a function?  4
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.  2
why java is platform independent? Wipro6
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h  1
Write a routine that prints out a 2-D array in spiral order Microsoft2
Find your day from your DOB? Microsoft11
How we will connect multiple client ? (without using fork,thread) TelDNA2
How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw... Oracle3
What is the main difference between STRUCTURE and UNION?  3
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com