C

Topic: Files

What are header files? Are functions declared or defined in header files ?

Functions and macros are declared in header files. Header files would be included in source files by the compiler at the time of compilation.Header files are included in source code using #include directive.#include<some.h> includes all the declarations present in the header file ‘some.h’.A header file may contain declarations of sub-routines, functions, macros and also variables which we may want to use in our program. Header files help in reduction of repetitive code.Syntax of include directive:#include<stdio.h> //includes the header file stdio.h, standard input output header into the source codeFunctions can be declared as well as defined in header files. But it is recommended only to declare functions and not to define in the header files. When we include a header file in our program we actually are including all the functions, macros and variables declared in it.In case of pre-defined C standard library header files ex(stdio.h), the functions calls are replaced by equivalent binary code present in the pre-compiled libraries. Code for C standard functions are linked and then the program is executed. Header files with custom names can also be created. Read more about header filesProgram: Custom header files example/****************Index: restaurant.h****************/int billAll(int food_cost, int tax, int tip);Download code/****************Index: restaurant.c****************/#include<stdio.h>int billAll(int food_cost, int tax, int tip) { int result; result = food_cost + tax + tip; printf("Total bill is %d\n",result); return result;}Download code/****************Index: main.c****************/#include<stdio.h>#include"restaurant.h"int main() { int food_cost, tax, tip; food_cost = 50; tax = 10; tip = 5; billAll(food_cost,tax,tip); return 0;}

Browse random answers:

What is File Mode?.Types Of file mode?.What is Pointer?.which one is most useful in Structure or Unoin?
How can you restore a redirected standard stream? 
how to read a file line by line and print it reverse 
WRITE C PROGRAMME TO CREATE A FILE AND READ A FILE. 
How to obtain a path of the given file?
If errno contains a nonzero number, is there an error?
What is a stream?
How do you redirect a standard stream?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
What is a file?
what are the types of file?
What is meant by file opening?
What is a file pointer?
How is a file closed ?
What is a random access file?
how to merge to file in c? 
Can include files be nested?
Write a program for creating your own header file and library function?
How can I open a file so that other programs can update it at the same time?
How can I create the batch files? What is the purpose batch file and use of it? 
How can we read/write structures from/to data files? 
In header files whether functions are declared or defined?
What will be the content of 'file.c' after executing the following program?#include&lt;stdio.h&gt;
int main(){ 
FILE *fp1, *fp2; 
fp1=fopen(&quot;file.c&quot;, &quot;w&quot;); fp2=fopen(&quot;file.c&quot;, &quot;w&quot;); 
fputc('A', fp1); 
fputc('B', fp2); 
fclose(fp1); 
fclose(fp2); 
return 0;
}
If the file 'source.txt' contains a line &quot;Be my friend&quot; which of the following will be the output of below program?
#include&lt;stdio.h&gt;
int main(){ 
 FILE *fs, *ft; 
char c[10]; 
fs = fopen(&quot;source.txt&quot;, &quot;r&quot;); 
c[0] = getc(fs); 
fseek(fs, 0, SEEK_END); 
fseek(fs, -3L, SEEK_CUR); 
fgets(c, 5, fs); 
puts(c); return 0;
}
What will be the output of the program ?#include&lt;stdio.h&gt;int main(){ 
FILE *ptr; char i; 
 ptr = fopen(&quot;myfile.c&quot;, &quot;r&quot;); while((i=fgetc(ptr))!=NULL) printf(&quot;%c&quot;, i); return 0;}
Out of fgets() and gets() which function is safe to use and why?
In a file contains the line &quot;I am a boyrn&quot; then on reading this line into the array str using fgets(). What will str contain?
Which of the following operations can be performed on the file &quot;NOTES.TXT&quot; using the below code?

FILE *fp;fp = fopen(&quot;NOTES.TXT&quot;, &quot;r+&quot;);
What is the purpose of ftell ?
What is the purpose of rewind() ?
What is the use of header file in c?
What are header files? Are functions declared or defined in header files ?
When we open a file, how does functions like fread( )/fwrite( ), etc. get to know from where to read or to write the data?
How to obtain a path of the given file?