Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Articles - Page 42 of 134
474 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
263 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
306 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
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
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
15K+ 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
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
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
441 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
1K+ Views
ProblemIn C language, is the program executed, if we use an uninitialized array?SolutionIf we use any uninitialized array, compiler will not generate any compilation and an execution error.If an array is uninitialized, you may get unpredictable result.So, it’s better we should always initialize the array elements with default values.Example ProgramFollowing is the C program of accessing an uninitialized array − Live Demo#include int main(void){ int a[4]; int b[4] = {1}; int c[4] = {1,2,3,4}; int i; //for loop counter //printing all alements of all arrays printf("Array a:"); for( i=0; i