Adobe Interview Question
Software Engineer / DevelopersI think using __FILE__ is more robust because the executable might not have the same name as the source file. We are assuming that the executable is in the same directory as the source file though.
sharat the question says that no input is provided so i doubt the use of command line arguments.
Well, i dont understand wht is logic behind asking such a problem .
One can simply read the same file and print it character by character.
Here is the code
#include <stdio.h>
int main()
{
FILE *fp;
char ch;
system("clear");
if ( (fp = fopen("adobe.c", "r")) == NULL )
{
printf ("error opening the file");
return 0;
}
while ( (ch = fgetc(fp)) != EOF )
{
putchar(ch);
}
}
Ok i wrote the code with an assumption that the name of the file shall be same as adobe.c
but i see the catch being that name shall be recieved as argument which is not allowed.
A little bit of googling gave me this
main(){char q=34, n=10,*a="main() {char q=34,n=10,*a=%c%s%c; printf(a,q,a,q,n);}%c";printf(a,q,a,q,n);}
Can somebody comment is this is what they are looking for.
int main()
- light April 20, 2012{
FILE* file = fopen(__FILE__,"r");
char ch;
while((ch=fgetc(file))!=EOF)
{
putchar(ch);
}
return 0;
}