- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
970 Views
First, open the file in write mode. Later on, enter the text until it reaches the End Of File (EOF) i.e. press ctrlZ to close the file.Again, open in reading mode. Then, read words from the file and print each word in a separate line and close the file.The logic we implement to print one word per line is as follows −while ((ch=getc(fp))!=EOF){ if(fp){ char word[100]; while(fscanf(fp, "%s", word)!=EOF) // read words from file{ printf("%s", word); // print each word on separate lines. } ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
981 Views
The structure is a user-defined data type, which is used to store a collection of different data types of data.The structure is similar to an array. The only difference is that an array is used to store the same data types whereas, the structure is used to store different data types.The keyword struct is for declaring the structure.Variables inside the structure are the members of the structure.A structure can be declared as follows −Struct structurename{ //member declaration };ExampleFollowing is the C program for accessing a structure variable − Live Demostruct book{ int pages; float price; char author[20]; ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
479 Views
The pointer is a variable that stores the address of another variable.The syntax for the pointer is as follows −pointer = &variable;ExampleFollowing is the C program for the concept of pointers using C language − Live Demo#include void main(){ //Declaring variables and pointer// int a=2; int *p; //Declaring relation between variable and pointer// p=&a; //Printing required example statements// printf("Size of the integer is %d", sizeof (int));//4// printf("Address of %d is %d", a, p);//Address value// printf("Value of %d is %d", a, *p);//2// printf("Value of next address location of %d is %d", a, ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
554 Views
ProblemHow to display and calculate the sum of n numbers by using dynamic memory allocation function in C language?SolutionFollowing is the C program to display the elements and calculate the sum of n numbers by the user by using dynamic memory allocation functions. Here, we also try to reduce the wastage of memory.Example Live Demo#include #include void main(){ //Declaring variables and pointers, sum// int numofe, i, sum=0; int *p; //Reading number of elements from user// printf("Enter the number of elements : "); scanf("%d", &numofe); //Calling malloc() function// p=(int *)malloc(numofe*sizeof(int)); /*Printing O/p - ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
863 Views
Let the user enter the numbers in an array, which contains duplicate elements.Now, let’s write a code to delete the repeated numbers or elements in an array and make an array with unique elements without duplicatesFor example, An example is explained below −User input is 12, 30, 12, 45, 67, 30.Output is 12, 30, 45, 67 (after deleting duplicates).ProgramFollowing is the C program to delete the duplicate numbers in an array − Live Demo#include #define MAX 100 // Maximum size of the array int main(){ int array[MAX]; // Declares an array of size 100 int size; int ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
1K+ Views
Converting upper to lower and lower to upper is generally termed as toggle.Toggle each character means, in a given string, the lower letter is print in upper form and upper case is print in lower letter respectively.ProgramThe C program to convert upper case to lower and lower case to upper is given below − Live Demo#include #define MAX 100 void toggle(char * string); int main(){ char string[MAX]; printf("enter the string need to be toggle :"); gets(string); toggle(string); printf("final string after toggling is:"); printf("%s", string); return 0; } void toggle(char * string){ int ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
598 Views
In this program, we are trying to check whether the two given numbers by the user through console, are friendly pair or not?ExampleIf sum of all divisors of number1 is equal to number1 and sum of all divisors of number2 is equal to number2, then we can say, those two numbers are abundant numbers.The logic that we used to find friendly pairs is as follows −For the sum of all divisors of number 1.for(i=1;i
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
1K+ Views
Squeeze(s1, s2) or squeeze(char[], char[]) is a user defined function which is used to delete the common characters or equal characters in two strings.ProblemHow to delete the common characters in two strings using squeeze function in C programming language?SolutionIn this program, the user enters two strings in the console and write a code to display first string excluding the common characters present in second string.ExampleThe C program which demonstrates the functioning of squeeze function is as follows − Live Demo#include void squeeze(char string1[], char string2[]);//prototype declaration int main(){ char string1[50]; char string2[30]; printf("enter the string1:"); scanf("%s", string1);// ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
495 Views
Else − if the ladder is the most general way of writing a multi-way decision.The syntax for else if the ladder is as follows −if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;FlowchartRefer the flowchart given below −ExampleFollowing is the C program to execute Else If Ladder conditional statement − Live Demo#include void main (){ int a, b, c, d; printf("Enter the values of a, b, c, d: "); scanf("%d%d%d%d", ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
962 Views
The different data types that we use in C programming are integer, short int, Signed and un signed char etc.Data TypesData type specifies the set of values and the type of data that can be stored in a variable. They allow the programmer to select the type appropriate to the needs of application.The data types are as follows −Primary data typesDerived data typesLet us understand primary data types.Primary data types‘C’ compilers support four fundamental data types. They are mentioned below −integercharacterFloating – pointDouble precision floating pointIntegral data typeIntegral data types are used to store whole numbers and characters. It is ... Read More