C Articles

Found 953 articles

How to wrap python object in C/C++?

Gireesha Devara
Gireesha Devara
Updated on 12-Mar-2026 648 Views

To wrap existing C or C++ functionality in Python, there are number of options available, which are: Manual wrapping using PyMethodDef and Py_InitModule, SWIG, Pyrex, ctypes, SIP, Boost.Python, and pybind1. Using the SWIG Module Let’s take a C function and then tune it to python using SWIG. The SWIG stands for “Simple Wrapper Interface Generator”, and it is capable of wrapping C in a large variety of languages like python, PHP, TCL etc. Example Consider simple factorial function fact() in example.c file. /* File : example.c */ #include // calculate factorial int fact(int n) { ...

Read More

C program to Replace a word in a text by another given word

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 6K+ Views

In this program, we have given three strings txt, oldword, newword. Our task is to create a C program to replace a word in a text by another given word.The program will search for all the occurrences of the oldword in the text and replace it with newword.Let’s take an example to understand the problem −Inputtext = “I am learning programming” oldword = “learning” newword = “practicing”Output“I am practicing programming”To solve this problem, we will first find the number of occurrence of the oldword in the string and then create a new string which will store the text with replaced ...

Read More

How to print a one-month calendar of user choice using for loop in C?

Mandalika
Mandalika
Updated on 11-Mar-2026 6K+ Views

The logic to print a one-month calendar is as follows −for(i=1;i

Read More

C program to sort an array in an ascending order

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 123K+ Views

Problem Sort the given array in descending or ascending order based on the code that has been written. Solution An array is a group of related data items which share’s a common name. A particular value in an array is identified with the help of its "index number". Declaring array The syntax for declaring an array is as follows − datatype array_name [size]; For example, float marks [50] It declares ‘marks’ to be an array containing 50 float elements. int number[10] It declares the ‘number’ as an array to contain a maximum of 10 integer constants. Each element is identified ...

Read More

C program to insert a node at any position using double linked list

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 2K+ Views

Linked lists use dynamic memory allocation and are collection of nodes.Nodes have two parts which are data and link.Types of Linked ListsThe types of linked lists in C programming language are as follows −Single / Singly linked lists.Double / Doubly linked lists.Circular single linked list.Circular double linked list.Double linked listThe diagram given below depicts the representation of double linked list.ExampleFollowing is the C program to insert a node at any position using double linked list −#include #include struct node {    int num;    struct node * preptr;    struct node * nextptr; }*stnode, *ennode; void DlListcreation(int n); ...

Read More

C program to count characters, lines and number of words in a file

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 16K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.ExampleConsider an example given below −Open a file in write mode.Enter statements in the file.The input file is as follows −Hi welcome to my world This is C programming tutorial From tutorials PointThe output is as follows −Number of characters = 72Total words = 13Total lines = 3ProgramFollowing is the C ...

Read More

C program to store even, odd and prime numbers into separate files

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 4K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.ProgramFollowing is the C program to store even, odd and prime numbers into separate files −#include #include /* Function declarations */ int even(const int num); int prime(const int num); int main(){    FILE * fptrinput,    * fptreven,    * fptrodd,    * fptrprime;    int num, success;   ...

Read More

C program to find GCD of numbers using recursive function

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 27K+ Views

ProblemFind the greatest common divisor (GCD) for the given two numbers by using the recursive function in C programming language.SolutionThe solution to find the greatest common divisor (GCD) for the given two numbers by using the recursive function is as follows −AlgorithmRefer an algorithm given below to find the greatest common divisor (GCD) for the given two numbers by using the recursive function.Step 1 − Define the recursive function.Step 2 − Read the two integers a and b.Step 3 − Call recursive function.a. if i>j b. then return the function with parameters i, j c. if i==0 d. then return ...

Read More

C program to remove a line from the file

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 10K+ Views

A file is a physical storage location on disk and a directory is a logical path which is used to organise the files. A file exists within a directory.The three operations that we can perform on file are as follows −Open a file.Process file (read, write, modify).Save and close file.AlgorithmAn algorithm is given below to explain the C program to remove a line from the file.Step 1 − Read file path and line number to remove at runtime.Step 2 − Open file in read mode and store in source file.Step 3 − Create and open a temporary file in write ...

Read More

C program to compute linear regression

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 9K+ Views

ProblemWrite a program to implement linear regression algorithm.User has to enter total number of values.SolutionThe solution to compute the linear regression in C programming language is as follows −Linear regression finds the relationship between two variables by connecting a linear equation to the observed data. One variable is to be an explanatory variable, and the other is a dependent variable.The logic with regards to linear regression is explained below −for(i=0;i

Read More
Showing 1–10 of 953 articles
« Prev 1 2 3 4 5 96 Next »
Advertisements