Bhanu Priya

Bhanu Priya

1,060 Articles Published

Articles by Bhanu Priya

Page 95 of 106

C Program to find minimum occurrence of character in a string

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 2K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.Finding minimum occurrenceThe logic to find minimum occurrence of a character in a given string is as follows −for(i=0; i

Read More

Write a C Program to count the frequency of each character

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 931 Views

Follow the algorithm to write a C program which enables to count the frequency of each character.AlgorithmStep 1: Define MAX size. Step 2: Declare char and integer variables. Step 3: Read the string from console. Step 4: Find length of the string. Step 5: Initialize frequency of each character to 0. Step 6: Find total number of occurrences of each character. for(i=0; i='a' && string[i]='A' && string[i]

Read More

Explain the Character operations in C language

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 695 Views

Character can be (A-Z(or) a- z), digit (0-9), a white space, or a special symbol in C programming language.DeclarationFollowing is the declaration for character operations in C programming −char a= ‘A’; using a character constant.Character input / output functionsThe character input/output functions are explained below −Example − char a;scanf("%c", &a); printf ("%c", &a); a = getchar ( ); putchar (a); a = getch ( ); putch (a);ExampleFollowing is the C program for line counting using getchar() − Live Demo#include /* count lines in input */ main(){    int count, num;    printf("enter multiple statements and Press cntrl+z:");    num = ...

Read More

Explain the pointers to unions in C language

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 4K+ Views

A union is a memory location that is shared by several variables of different data types.SyntaxThe syntax for the pointers to unions in C programming is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };ExampleThe following example shows the usage of union of structure.union sample{    int a;    float b;    char c; };Declaration of union variableFollowing is the declaration for union variable. It is of three types as follows −Type 1union sample{    int a;    float b;    char c; }s;Type 2union{    int a; ...

Read More

Explain linear data structure queue in C language

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 856 Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below −Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists.Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables.QueueIt is a linear data structure, where the insertion is done at rear end and the deletion is done at the front end.The order of queue is FIFO – First In First OutOperationsInsert – Inserting an element into a queue.Delete – Deleting an element from the ...

Read More

What is a structure at local scope in C language?

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 985 Views

Structure is a collection of different datatype variables, grouped together under a single name.General form of structure declarationThe structure declaration is as follows −struct tagname{    datatype member1;    datatype member2;    datatype member n; };Here, struct is the keyword.tagname specifies name of structure.member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of the structure at a local scope.struct book{    int pages;    char author [30];    float price; };ExampleThe following program shows the usage the structure at a local scope. Live Demo#include struct{    char name[20];    int age;    int salary;   ...

Read More

Explain C Error handling functions

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 947 Views

File is collection of records or is a place on hard disk, where data is stored permanently.Operations on filesThe operations on files in C programming language are as follows −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxThe syntax for opening a file is as follows −FILE *File pointer;For example, FILE * fptr;The syntax for naming a file is as follows −File pointer = fopen ("File name", "mode");For example, fptr = fopen ("sample.txt", "r"); FILE *fp; fp = fopen ("sample.txt", "w");Error Handling in FilesSome of the errors in files are as follows −Trying to read beyond ...

Read More

How to pass an entire structure as an argument to function in C?

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 4K+ Views

There are three ways by which the values of structure can be transferred from one function to another. They are as follows −Passing individual members as arguments to function.Passing entire structure as an argument to function.Passing the address of structure as an argument to function.Now let’s see how to Pass an entire structure as an argument to function.Name of the structure variable is given as argument in function call.It is collected in another structure variable in function header.The disadvantage is that a copy of an entire structure is created again by wasting the memory.ExampleThe following program shows how to pass ...

Read More

Explain the dynamic memory allocation of pointer to structure in C language

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 5K+ Views

Pointer to structure holds the add of the entire structure.It is used to create complex data structures such as linked lists, trees, graphs and so on.The members of the structure can be accessed using a special operator called as an arrow operator ( -> ).DeclarationFollowing is the declaration for pointers to structures in C programming −struct tagname *ptr;For example: struct student *s;AccessingIt is explained below how to access the pointers to structures.Ptr-> membername;For example − s->sno, s->sname, s->marks;ExampleFollowing is a C program that explains the dynamic memory allocation of structure in C programming − Live Demo#include #include struct person ...

Read More

Explain append mode operation of files in C language

Bhanu Priya
Bhanu Priya
Updated on 24-Mar-2021 764 Views

File is collection of records or is a place on hard disk, where data is stored permanently.Need of filesEntire data is lost when a program terminates.Storing in a file preserves the 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.We can easily access the content of files by using few commands.You can easily move your data from one computer to another without changes.By using C commands, we can access the files in different ways.Operations on filesThe operations on files in C programming language ...

Read More
Showing 941–950 of 1,060 articles
« Prev 1 93 94 95 96 97 106 Next »
Advertisements