Found 1401 Articles for C

Explain feof() function in C language with a program

Bhanu Priya
Updated on 13-Mar-2021 11:18:45

354 Views

ProblemHow the C compiler detect that the file was reached the end for while reading? Explain with a program.Solutionfeof() is a file handling function in C language, which is used to find end of a file.The logic we used for finding end of file is as follows −fp = fopen ("number.txt", "r"); //open a file printf ("file content is"); for (i=0;i

How to print the content into the files using C language?

Bhanu Priya
Updated on 11-Mar-2021 07:51:00

180 Views

We can write a program in C for printing some content in to the file and print the following −Number of characters entered into the file.Reverse the characters entered into the file.First, try to store number of characters into the file by opening the file in write mode.For entering data into file, we use the logic as mentioned below −while ((ch = getchar( ))!=EOF) {//after enter data press cntrl+Z to terminate    fputc(ch, fp); }With the help of ftell, rewind, fseek functions, we can reverse the content that we already entered into the file.ExampleGiven below is a C program for ... Read More

C program to display relation between pointer to pointer

Bhanu Priya
Updated on 11-Mar-2021 07:10:58

248 Views

In C programming language, pointer to pointer or double pointer is a variable that holds the address of another pointer.DeclarationGiven below is the declaration for pointer to pointer −datatype ** pointer_name;For example, int **p;Here, p is a pointer to pointer.Initialization‘&’ is used for initialization.For example, int a = 10; int *p; int **q; p = &a;AccessingIndirection operator (*) is used for accessingSample programFollowing is the C program for double pointer − Live Demo#include main ( ){    int a = 10;    int *p;    int **q;    p = &a;    q = &p;    printf("a =%d ", a);   ... Read More

C Program for copying the contents of one file into another file

Bhanu Priya
Updated on 11-Mar-2021 07:09:19

18K+ Views

File is a collection of records (or) is a place on hard disk, where data is stored permanently. By using C commands, we can access the files in different ways.Operations on filesThe operations that can be carried out on files in C language are as follows −Naming the file.Opening the file.Reading from the file.Writing into the file.Closing the file.SyntaxThe syntax for opening and naming file is as follows −FILE *File pointer;For example, FILE * fptr;File pointer = fopen ("File name”, "mode”);For example, fptr = fopen ("sample.txt”, "r”);FILE *fp; fp = fopen ("sample.txt”, "w”);The syntax for reading from file is as ... Read More

What are the different operations on files in C language?

Bhanu Priya
Updated on 11-Mar-2021 06:56:26

6K+ Views

The operations that can be carried out on files in C language are as follows −Naming the file.Opening the file.Reading from the file.Writing into the file.Closing the file.SyntaxThe syntax for opening and naming file is as follows −FILE *File pointer;For example, FILE * fptr;File pointer = fopen ("File name”, "mode”);For example, fptr = fopen ("sample.txt”, "r”)FILE *fp; fp = fopen ("sample.txt”, "w”);Modes of opening the fileThe modes of opening the file in C language are explained below −ModesDescriptionrFile is opened for readingwFile is opened for writinga+File opened for appendr+File opened for reading & writingw+File opened for writing & readinga+File opened ... Read More

What are the text files and binary files in C language?

Bhanu Priya
Updated on 09-Mar-2021 10:05:14

12K+ Views

Files is collection of records (or) it is a place on hard disk, where data is stored permanently.Types of FilesThere are two types of files in C language which are as follows −Text fileBinary FileText FileIt contains alphabets and numbers which are easily understood by human beings.An error in a text file can be eliminated when seen.In text file, the text and characters will store one char per byte.For example, the integer value 4567 will occupy 2 bytes in memory, but, it will occupy 5 bytes in text file.The data format is usually line-oriented. Here, each line is a separate ... Read More

Why files are needed in C programming language?

Bhanu Priya
Updated on 09-Mar-2021 10:04:35

3K+ Views

Files is collection of records (or) it is a place on hard disk, where data is stored permanently. By using C commands, we access the files in different ways.Need of files in C languageEntire data is lost when the program terminates and storing in a file will preserve your data even if the program terminates.If you want to enter a large amount of data, normally, it takes a lot of time to enter them all.If you have a file containing all the data, you can easily access the contents of the file by using few commands in C.You can easily ... Read More

How to define pointer to pointer in C language?

Bhanu Priya
Updated on 09-Mar-2021 10:00:54

331 Views

Declaring double pointer is similar to declaring pointer in C programming language. The difference is that only we need to add an additional ‘*’ before the name of pointer.SyntaxThe syntax is given below for declaring double pointers −int **ptr;ExampleFollowing is the C program for pointer to pointer − Live Demo#include // C program to demonstrate pointer to pointer int main(){    int element = 24;    // pointer for element    int *ptr2;    // double pointer for ptr2    int **ptr1;    // storing address of value in ptr2    ptr2 = &element;    // Storing address of ptr2 in ... Read More

Explain the Union to pointer in C language

Bhanu Priya
Updated on 09-Mar-2021 09:57:33

894 Views

A union is called as a memory location, which is shared by several variables of different data types.SyntaxThe syntax is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };For example, union sample{    int a;    float b;    char c; };Declaration of union variableGiven below are the respective declarations of union variable −Union sample{    int a;    float b;    char c; }s;Union{    int a;    float b;    char c; }s;Union sample{    int a;    float b;    char c; }; union sample ... Read More

Write a structure in local scope program using C language

Bhanu Priya
Updated on 09-Mar-2021 09:53:13

331 Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure are explained below −It is possible to copy the contents of all structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling complex datatypes, it is better to create a structure within an another structure, which is called as the nested structures.It is possible to pass an entire structure, individual elements of a structure and an address of structure to a function.It is also possible to create the structure pointers.Declaration of structuresThe general ... Read More

Advertisements