Found 1339 Articles for C

Explain the sorting techniques in C language

Bhanu Priya
Updated on 09-Dec-2024 16:28:32

42K+ Views

In this article, we are going to learn about the different sorting techniques and their implementations in C language. Sorting in C programming requires rearranging elements in the array into a determined order, i.e., in ascending or descending order. This will use the comparison operator to specify the new order of a list or array. This is widely used in different applications that include searching algorithms, data structure optimization, and database management. The following are the sorting techniques that we can implement with C language and other programming also: ... Read More

Explain feof() function in C language with a program

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

461 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

253 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

295 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

23K+ 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 12-Dec-2024 16:59:58

8K+ Views

A file is a collection of data stored in secondary memory. The data is entered directly from the keyboard, files are used to store both information and programs. The following operations can be performed on files in the C language − Naming the file. Opening the file. Reading from the file. Writing into the file. Closing the file. File Naming and Opening The syntax for opening and naming file is as follows − FILE *File pointer; For ... Read More

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

Bhanu Priya
Updated on 12-Dec-2024 17:26:32

14K+ Views

A file is a collection of data stored in secondary memory, used for storing information that can be processed. Files allow data to be saved and retrieved later. They can store both programs and data, making file input and output operations crucial for reading from and writing to files. There are two types of files in C language which are as follows − Text file Binary File Text File Text files contain alphabets and numbers that are easily understood by humans. Errors in text files can be easily identified and ... Read More

Why files are needed in C programming language?

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

4K+ 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

Explain the Union to pointer in C language

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

1K+ 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

425 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