Oracle Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
4
of 4 vote

void copyFile()
{
FILE *fileSrc, *fileDest;
char c;
fileSrc = fopen("file1","ro");
fileDest = fopen("file2","w");
while((c=fgetc(fileSrc)!= EOF)
fputc(fileDest,c);
}

- Anonymous April 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think better use some intermediate buffer with fread/fwrite instead to minimize the number of calls to library functions

- Anonymous April 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

-1
too slow , it is not efficient();

unsigned int copyfile(FILE *p, FILE *q)
{
	char buf[4096]={0};
	int readbytes=0,writebytes=0;
	int count=0;
	//fseek(p,0,SEEK_SET);
	while(readbytes=fread(buf,1,4096,p))
	{

		if((readbytes!=4096)&&(!feof(p)))
		{
		 printf("%d",ferror(p));
         return 0;
		}
		if(writebytes=fwrite(buf,1,readbytes,q))
		{
			if(writebytes!=readbytes)
			{
				printf("%d",ferror(q));
				return 0;
			}
			count=count+writebytes;
		}
		if(readbytes!=4096) break;
	 
	}
	return count;
}

}

- Charles December 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
    Usage: copy <infile> <outfile>
    Copies infile to outfile BUFSZ bytes at a time.

    Does not handle interrupted syscalls.
    Exit value is 0 on success, non-zero otherwise.
    Primitive error checking with assert.
*/

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>

#define BUFSZ 1024

int
main(int argc, char *argv[])
{
        assert(argc == 3);
        int readfd = open(argv[1], O_RDONLY);
        assert(readfd >= 0);
        int writefd = open(argv[2], O_WRONLY|O_CREAT);
        assert(writefd >= 0);
        char buf[BUFSZ];
        ssize_t len;
        while ((len = read(readfd, buf, BUFSZ)) > 0)
                if (write(writefd, buf, len) != len)
                        goto error;
        if (len < 0)
                goto error;
        close(readfd);
        close(writefd);
        return 0;

error:
        return 1;
}

- Event Horizon April 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More