CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
File Operations in C Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C INTERVIEW QUESTIONS FILE OPERATIONS IN C INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

File Operations in C Interview Questions & Answers - Learning Mode

File stores information for many purposes and retrieve whenever required by our programs. A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. C programming language can handle files as Stream-oriented data (Text) files and System oriented data Binary) files. You can use the fopen( ) function to create a new file or to open an existing file. This call will initialize an object of the type FILE, which contains all the information necessary to control the stream. To close a file, use the fclose( ) function. The function fputc() writes the character value of the argument c to the output stream referenced by fp. It returns the written character written on success otherwise EOF if there is an error.

Try File Operations in C Interview Questions & Answers - Exam Mode

1

Sort By : Latest First | Oldest First | By Rating

File Operations in C Interview Questions & Answers - Learning Mode
Try File Operations in C Interview Questions & Answers - Exam Mode
Question: How can I open a file so that other programs can update it at the same time?

Answer: Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE.EXE. Shared mode, as the name implies, allows a file to be shared with other programs as well as your own.

Using this function, you can allow other programs that are running to update the same file you are updating.

The sopen() function takes four parameters: a Source: CoolInterview.com
Question: 1.WAP find the largest of 4 no using macros
2.WAP read a line from file from location N1 to N2 using command line agruments Eg:exe 10 20 a.c


Answer: Ans 1: #define max(a,b,c,d) (((a>b?a:b) > (c>d?c:d) ) ? (a>b?a:b) : (a>b?a:b)) Source: CoolInterview.com
Question: How can we read/write structures from/to data files?

Answer:
Question: How can I make sure that my program is the only one accessing a file?

Answer: By using the sopen() function you can open a file in shared mode and explicitly deny reading and writing permissions to any other program but yours. This task is accomplished by using the SH_DENYWR shared flag to denote that your program is going to deny any writing or reading attempts by other programs.

For example, the following snippet of code shows a file being opened in shared mode, denying
access to all other files:

/* Note that the sopen() function is not ANSI compliant. Source: CoolInterview.com
Question: If we develop a project in C, then how can we create an exe file of it?



Answer: Assume Your Project Contains 3 different files + 1 main file containing main() function

Required Steps 2 Compile are:

1) Add/Link The File To The File Containing main() function by using preprocessor statements i.e

#include"<filename>"

#include"<filename>"

#include"<filename>"

#include"<filename>"

2) Use Compile Option or Use Compile Project

Source: CoolInterview.com
Question: What is the difference between text and binary modes?

Answer: Streams can be classified into two types: text streams and binary streams. Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations are translated to the newline n character and vice versa. Binary streams are uninterpreted and are treated one byte at a time with no translation of characters. Typically, a text stream would be used for reading and writing standard text files, printing output to the screen or printer, or receiv Source: CoolInterview.com
Question: Can include files be nested?

Answer: Yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency tracking function of the MAKE program and thus slows down compilation. Many of today?s popular compilers make up for this difficulty by implementing a concept called precompiled headers, in which all headers and associated dependencies are stored Source: CoolInterview.com
Question: How can you restore a redirected standard stream?

Answer: The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state.

The dup() function duplicates a file handle. You can use the dup() function to save the file handle
corresponding to the stdout standard stream. The fdopen() Source: CoolInterview.com
Question: Write a program for creating your own header file and library function?

Answer: int fact(int n)
{ int f=1;
if(n>7)
{
printf("SORRy We can't find a factorial for a no>7");
return -1;
}
while(n)
f=f*n00;
return f;
}
now this function save as myfuns.h
if u want to reuse this function in any another programme then .......
You first write this header file name with codes like # include "myfuns.h" .after that u can write ur programme and u can cal and use fact fun in this entire programme.... Source: CoolInterview.com
Question: What is File Mode?.
Types Of file mode?.
What is Pointer?.
which one is most useful in Structure or Unoin?.


Answer: the meaning of file mode means in which mode we want to open the file.types of modes are read mode,write mode.pointer is the variable which holds the address of another variable.union r useful bcoz of memory no wastage but structures r frequently used than unions. Source: CoolInterview.com
Question: How can I create the batch files? What is the purpose batch file and use of it?

Answer: Batch files is to make your work easy. instead of executing the command one by one, just write the commands to be executed in a notepad and store as a .bat
Now type the name of bat file in the exceute path , it starts to execute the commands you have inside of the batch file Source: CoolInterview.com
Question: What is the benefit of using an enum rather than a #define constant?

Answer: The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability, and better debugging capability.
The first advantage is that enumerated constants are generated automatically by the compiler. Conversely, symbolic constants must be manually assigned values by the programmer.
For instance, if you had an enumerated constant type for error codes th Source: CoolInterview.com
Question: How do you redirect a standard stream?

Answer: Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; it can be redirected to a file or printer port. Similarly, your program?s input (stdin) can come from a file rather than the keyboard. In DOS, this task is accomplished using the redirection characters, < and >. For example, if you wanted a program named PRINTIT.EXE to receive its input (stdi Source: CoolInterview.com
Question: read a A file aaaaabbbbb.. and read a B file 111112222... in c file to write aaaaa11111bbbbb22222 like this?

Answer: Read the contents of file a in a buffer ... fileA. Read the contents of file B in a buffer fileB
Read the first character of the buffer fileA in a variable sample. Now start going through the buffer. The moment you hit a char which is not same as sample, change the value of sample to this new character and now start reading from fileB. Source: CoolInterview.com
Question: how to merge to file in c?

Answer: Merging to a file is simply appending to a file.Try it. Source: CoolInterview.com
Question: Can include files be nested?

Answer: Yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency tracking function of the MAKE program and thus slows down compilation. Many of today?s popular compilers make up for this difficulty by implementing a concept called precompiled headers, in which all headers and associated dependencies are stored Source: CoolInterview.com

1



India News Network
Latest 20 Questions
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
"Holiday Packages" announced as an advertisement are an example of _________: (a) Offer (b) Counter Offer (c) Invitation to Offer (d) None of the above
A match fixing contract between a player and a broker is a: (a) Valid Contract (b) Unenforceable Contract (c) Void Contract (d) Illegal Contract
When a bookseller sells a book on cash payment then it is called as ___________: (a) Unilateral Contract (b) Bilateral Contract (c) Executed Contract (d) Executory Contract
____________ agreements are created by situation: (a) Written (b) Oral (c) Void (d) Implied
Cache = 0.328125 Seconds