- 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)
688 Views
ProblemWrite a C program to concatenate n characters from source string to destination string using strncat library functionSolutionThe strcat functionThis function is used for combining or concatenating two strings.The length of the destination string must be greater than the source string.The resultant concatenated string will be in the source string.Syntaxstrcat (Destination String, Source string);Example 1#include main(){ char a[50] = "Hello"; char b[20] = "Good Morning"; clrscr ( ); strcat (a, b); printf("concatenated string = %s", a); getch ( ); }OutputConcatenated string = Hello Good MorningThe strncat functionThis function is used for combining or ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
3K+ Views
Strncmp is a predefined library function present in string.h file, it used to compare two strings and display which string is greater.The strcmp fucntion (String comparison)This function compares 2 strings. It returns the ASCII difference of the first two non– matching characters in both the strings.Syntaxint strcmp (string1, string2);If the difference is equal to zero, then string1 = string2.If the difference is positive, then string1> string2.If the difference is negative, then string1 0) { printf("%s is greater than %s", string1, string2); } else { printf("%s is less than %s", string1, string2); } ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
15K+ Views
ProblemHow to read a series of items that are present in a file and display the data in columns or tabular form using C ProgrammingSolutionCreate a file in write mode and write some series of information in the file and close it again open and display the series of data in columns on the console.Write mode of opening the fileFILE *fp; fp =fopen ("sample.txt", "w");If the file does not exist, then a new file will be created.If the file exists, then old content gets erased & current content will be stored.Read mode of opening the file FILE *fp fp =fopen ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
205 Views
Open a file in reading mode. If the file exists, then write a code to count the number of lines in a file. If the file does not exist, it displays an error that the file is not there.The file is a collection of records (or) It is a place on the hard disk where data is stored permanently.Following are the operations performed on files −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxFollowing is the syntax for opening and naming a file −1) FILE *File pointer; Eg : FILE * fptr; 2) File pointer ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
957 Views
A pointer is a variable that stores the address of another variable.Features of PointersPointer saves the memory space.The execution time of a pointer is faster because of direct access to memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used with data structures.Declaring a pointerint *p;It means ‘p’ is a pointer variable that holds the address of another integer variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.For example, int qty = 175; int *p; p= &qty;Accessing a variable through its pointerTo access the value of ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
751 Views
ProblemWrite a C program to define the structure and display the size and offsets of member variablesStructure − It is a collection of different datatype variables, grouped together under a single name.General form of structure declarationdatatype member1; struct tagname{ datatype member2; datatype member n; };Here, struct - keywordtagname - specifies name of structuremember1, member2 - specifies the data items that make up structure.Examplestruct book{ int pages; char author [30]; float price; };Structure variablesThere are three ways of declaring structure variables −Method 1struct book{ int pages; char author[30]; float price; }b;Method 2struct{ ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
1K+ Views
ProblemMention some of the legal and illegal declarations and initializations while doing C programming?Before discussing the legal and illegal statements let’s see how to declare and initialize the variables in C.Variable declarationFollowing is the syntax of variable declaration −SyntaxDatatype v1, v2, … vn;Where v1, v2, ...vn are names of the variables.For example, int sum;float a, b;Variable can be declared in two ways −local declarationglobal declarationThe ‘local declaration’ is declaring a variable inside the main block and its value is available within that block.The ‘global declaration’ is declaring a variable outside the main block and its value is available throughout the ... Read More
![Bhanu Priya](https://www.tutorialspoint.com/assets/profiles/314653/profile/60_78287-1615027882.jpg)
2K+ Views
In this program, we are adding random numbers that are generated in between 0 and 100.After every runtime, the result of sum of random numbers is different, i.e., we get a different result for every execution.The logic we use to calculate the sum of random numbers in between 0 to 100 is −for(i = 0; i
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
6K+ Views
ProblemHow to store the cricketer’s data in tabular form in sorted order based on average runs using structures in C Programming language.SolutionLet’s try to enter the cricketer information such as name, age, no of matches and average runs he scored. It will be entered in the console at runtime using the structure concept.And try to display the information in tabular form in sorted order based on average runs scored by each person so that it is easy to identify each person's details clearly.The logic we used to sort the cricketers in ascending order based on average runs they scored is ... Read More
![Mandalika](https://www.tutorialspoint.com/assets/profiles/223769/profile/60_143952-1595686763.jpg)
754 Views
ProblemEnter a sentence at run time and write a code for calculating the average length of words that are present in a sentenceSolutionAlgorithmSTART Step 1: declare character, int and double variables Step 2: Enter any statement Step 3: while loop Check condition stmt[i]=getchar()) != '' True then enter into loop Increment I and call the function at step 5 Step 4: Print the average length return by function From step 5 Step 5: called function calculatewordlength i. declare and initialize ... Read More