Found 1401 Articles for C

How to add “graphics.h” C/C++ library to gcc compiler in Linux

Ayush Gupta
Updated on 25-Feb-2020 07:25:35

1K+ Views

In this tutorial, we will be discussing a program to understand how to add “graphics.h” C/C++ library to gcc compiler in Linux.To do this we are required to compile and install the libgraph package.This includes install build-essential and some external packages>>sudo apt-get install build-essential >>sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-devThen setting the path in the extracted files>>sudo make install >>sudo cp /usr/local/lib/libgraph.* /usr/libExample#include #include #include int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, NULL);    circle(40, 40, 30);    delay(40000); ... Read More

How does a vector work in C/C++

Ayush Gupta
Updated on 25-Feb-2020 07:20:01

2K+ Views

In this tutorial, we will be discussing a program to understand how vectors work in C/C++.A vector data structure is an enhancement over the standard arrays. Unlike arrays, which have their size fixed when they are defined; vectors can be resized easily according to the requirement of the user.This provides flexibility and reduces the time requirement with arrays to copy the previous elements to the newly created array.Example Live Demo#include #include using namespace std; int main(){    vector myvector{ 1, 2, 3, 5 };    myvector.push_back(8);    //not vector becomes 1, 2, 3, 5, 8    for (auto x : myvector)    cout

How arrays are passed to functions in C/C++

Ayush Gupta
Updated on 17-Feb-2020 10:09:38

72 Views

In this tutorial, we will be discussing a program to understand how arrays are passed to functions.In the case of C/C++, the arrays are passed to a function in the form of a pointer which provides the address to the very first element of the array.Example Live Demo#include //passing array as a pointer void fun(int arr[]){    unsigned int n = sizeof(arr)/sizeof(arr[0]);    printf("Array size inside fun() is %d", n); } int main(){    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};    unsigned int n = sizeof(arr)/sizeof(arr[0]);    printf("Array size inside main() is %d", n);   ... Read More

Predefined Identifier __func__ in C

sudhir sharma
Updated on 04-Feb-2020 07:30:13

2K+ Views

Identifier is the name given to an entity in programming to identify it in the program.Generally, identifiers are created by the programmer for efficient working but there are some predefined identifiers that are inbuilt in programming. For example, cout, cin, etc.Here, we will see one of these predefined identifiers of C programming language which is __func__.The formal definition of __func__ is  −“The identifier __func__ shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declarationstatic const char __func__[] = “function-name”;appeared, where function-name is the name of the lexically-enclosing function.”C program The ... Read More

Print * in place of characters for reading passwords in C

sudhir sharma
Updated on 03-Feb-2020 10:20:11

511 Views

In this problem, we are given a string password. Our task is to print * in place of characters of the password.Let’s take an example to understand the problem,Input: password Output ********To solve this problem, we will traverse the password we have entered and print * in place of characters of the password.ExampleThe below program will show the implementation of our solution Live Demo#include #include int main() {    char password[50] = "password";    int length = strlen(password);    printf("Password : ");    for(int i = 0; i

Print 1 2 3 infinitely using threads in C

sudhir sharma
Updated on 03-Feb-2020 10:15:24

342 Views

Here, we have to print 1 2 3 sequences repeatedly infinite number of times using threads in the c programming language.Let’s see the sample output that we want from our code, 1 2 3 1 2 3 1 2 3 1 2 3For this, we will have to use three threads that are running side by side in the C programming language. And a variable that is initialized to one in the first thread whose value will be updated based on its last value. And run an infinite loop in the function.ExampleLet’s see the program to implement our solution, #include ... Read More

Print 2D matrix in different lines and without curly braces in C/C++

sudhir sharma
Updated on 03-Feb-2020 09:58:11

198 Views

Here, we will see the code that will print a 2D matrix in c/c++ programming language without using curly braces.Curly braces are separators in a programming language that are used to define separate code blocks in the program. Without curly braces defining scopes is difficult in c/c++.Let’s see the basic code and sample output to print 2D matrix.Example Live Demo#include using namespace std; int main() {    int arr[2][2] = {{12, 67},    {99, 5}};    int n = 2, m = 2;    for (int i = 0; i < m; i++){       for (int j = 0; j < n; j++){          cout

Integer to Roman in C

Arnab Chakraborty
Updated on 27-Apr-2020 11:57:00

5K+ Views

Given a decimal number n, we have to convert this into Roman numeral. The value n lies in the range 1 to 4000. These are some Roman Numerals.NumberNumeral1I4IV5V9IX10X40XL50L90XC100C400CD500D900CM1000M4000MMMMSo if the number n = 859, its Roman Numeral will be DCCCLIXTo solve this, we will follow these stepsDefine an array to store numeral and corresponding values for the given list. That is called nume arraywe are using a recursive approach, the function decToRom() is used. this is taking nume array and the number num.The decToRom() will be likeif num is not 0, thenmax := find maximum value from nume array that ... Read More

C program for file Transfer using UDP?

Arnab Chakraborty
Updated on 29-Jan-2020 12:18:08

1K+ Views

Data can be shifted between two computers implementing Socket programming in C.In same case, files can easily be sent implementing User Datagram Protocol(UDP) and a simple client/server.Security − Handled by encryption.Protocol − UDPEncryption − XOR encryptionAlgorithmThe server is started and waited for filename.A filename is sent by the client.This filename is received by the server. If file is present, server starts reading file and is continued to send a buffer filled with file contents encrypted until and unless file-end is reached.End of File is marked by EOF.File is received as buffers until and unless EOF is received. After that it ... Read More

Binary Number System - Overflow in Arithmetic Addition in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:43:59

577 Views

2’s Complement Number System is widely implemented in computer architecture.N-bit 2’s Complement number System can be able to represent Number from -2n-1 to 2n-1- 14 Bit can be able to represent numbers from ( -8 to 7 )5 Bit can be able to represent numbers from ( -16 to 15 ) in 2’s Complementary System.Overflow happens with respect to addition when 2 N-bit 2’s Complement Numbers are appended and the answer is too large to fit into that N-bit Group.A computer contains N-Bit Fixed registers. Result of addition of two N-Bit Number will result maximum N+1 Bit number.Carry Flag stores ... Read More

Advertisements