Want to run Windows application on your Raspberry Pi desktop? Try out Wine. It’s a multi-format reader designed specially to run Windows applications on different platforms such as Linux, Debian, Fedora and so on. It’s a lightweight compatibility layer that efficiently runs on your Raspberry Pi desktop without reducing the device performance.

This guide will show you how you can install Wine on your Raspberry Pi device and install Windows applications with ease.

How to run Windows Applications on Raspberry Pi using Wine

Installing Wine on Raspberry Pi is pretty simple, thanks to the Raspberry Pi developers, which includes the repository of Wine, making it easier for you to install the application. The below-given steps will guide you in installing Wine in on Raspberry Pi:

Step 1: Update Raspberry Pi Packages

Before installing any application, ensure that your packages are updated. To confirm it, execute the following command:

$ sudo apt update && sudo apt upgrade

Step 2: Adding i386 Architecture

Wine works on i386 architecture and if you are using other architecture you will need to change it using the following command:

$ sudo dpkg –add-architecture i386

Step 2: Install Wine

After completing the above steps, you can install Wine on Raspberry Pi using the following command:

Enter “Y” to begin the Wine installation on your Raspberry Pi device.

After completing the installation, open Wine configuration on your Raspberry Pi device using the following command:

The above command will open the Wine configuration. You can select your Windows version according to your choice.

Installing Windows Application on Raspberry Pi

Now, to install an application on Raspberry Pi, you will first need to download a Windows application in “.exe” format.

In our case, we are going to download the VLC media player as an example for you to learn how you can install Windows applications. After the download, look for the location where your file is downloaded. It may differ in your case, but mostly, it’s located in the “Downloads” directory.

To install the application, first visit the location in the terminal using the following command:

Then use the following command to run the application using Wine.

$ wine <application_name>

Complete the remaining installation steps to install VLC media player on your Raspberry Pi OS. Then issue the following command to run the VLC media player on Raspberry Pi.

In this way, you can install multiple Windows applications with ease.

Conclusion

Wine is a perfect solution that allows Raspberry Pi users to install and run Windows applications easily. The installation of Wine on Raspberry Pi is quiebro simple, as mentioned in the above guidelines, it requires only an i386 architecture and an installation command. After installing, you can download any Windows application and run it on the terminal using the “wine” command with the application name.



Source link


Jellyfin is a free and open-source online media solution designed to manage, organize and share media files to other networked devices. It lets you run your media files directly onto your browser via its web dashboard. You can install it on any platform, such as Windows, Linux and macOS.

If you want to install Jellyfin on Raspberry Pi, you should follow the guidelines provided in the article so that you will be able to access the Jellyfin web interface.

Installing Jellyfin on Raspberry Pi

The Raspberry Pi OS doesn’t include the Jellyfin repository; thus, you cannot install it directly onto your system. After adding the repository, you can then install it on your device. The following simple steps-by-step instructions will help you in installing Jellyfin on your Raspberry Pi device:

Step 1: Update Packages list of Raspberry Pi

Initially, you will need to update your packages list installed on your Raspberry Pi through following command:

$ sudo apt update && sudo apt upgrade

Step 2: Add GPG Key

Now add GPG key using the following command to verify the package authenticity:

$ sudo wget -O- https://repo.jellyfin.org/jellyfin_team.gpg.key | gpg –dearmor | sudo tee /usr/share/keyrings/jellyfin.gpg

Step 3: Add Jellyfin Repository

By updating the packages on Raspberry Pi, it’s now time to add Jellyfin repository in Raspberry Pi repository list through following command:

$ echo «deb [arch=$( dpkg –print-architecture ) signed-by=/usr/share/keyrings/jellyfin.gpg] https://repo.jellyfin.org/debian bullseye main» | sudo tee /etc/apt/sources.list.d/jellyfin.list

Step 4: Update Raspberry Pi Repository List

After adding the Jellyfin repository, use the following command to update the Raspberry Pi repository list.

Step 5: Install Jellyfin

After the update, you can install the Jellyfin on your Raspberry Pi device through following command:

$ sudo apt install jellyfin

Check Jellyfin version through following command:

The above output shows that the latest version of Jellyfin is installed on your system.

You can check the Jellyfin running status using the following command:

$ systemctl status jellyfin

To enable Jellyfin after the system reboots, use the following command:

$ sudo systemctl enable jellyfin

Step 6: Access the Jellyfin Web Interface

Now, to access the Jellyfin web interface on your browser, first you will need to find out your Raspberry Pi IP address using the following command:

Then use the address “http://192.168.18.218:8096” on your browser to open the web interface of Jellyfin. In the address, change the IP address with your device IP address.

This will open the Jellyfin welcome page on your browser. Proceed towards the next step using the “Next” option.

Set your Jellyfin account username and password.

You can click on the “Add Library” to add your media files from here or simply choose the “Next” button to add the files later.

Choose your language,

Allow remote connections and proceed to the next step.

Click on the “Finish” option to view Jellyfin dashboard.

Sign in with your Jellyfin account.

This shows the Jellyfin dashboard on your browser.

Now, you can add media libraries such as photos, videos and any other file and can run it on your browser because the Jellyfin server is now successfully loaded up on your browser.

This completes the Jellyfin setup.

Conclusion

Jellyfin is an open-source online application that allows access to the media from an online server. On Raspberry Pi, you can install it by adding the source repository and using the apt installer. You can then access Jellyfin dashboard on any web browser using the Raspberry Pi IP address and with proper configuration, you will then be able to use its web interface.



Source link


There are several types of operators are present in C languages. With these operators, we can manipulate different types of operands or data with different procedure. Arithmetic operator is one of the operators by which we can operate different types of mathematical values. First, we have to see that what the position of arithmetic operator in operator groups is.

Operator Groups:

  • Unary operators
  • Arithmetic operators
  • Bitwise operators
  • Relational operators
  • Logical operators
  • Conditional operators
  • Assignment operators

One kind of proceeding rules, if in a problem there are multiple operator present, then this type of problem is solved according to this order of operator groups. This means:

Unary -> Arithmetic -> Bitwise -> So on.

Arithmetic Instruction:

Arithmetic Instruction is an Instruction which is used to manipulate data using operators.

Example:

1

3    +     4     *    5

One result may be 23 another may be 35.

A result is Right, another is wrong. We use operator proceeding BODMAS. But in C language, there is no rule of BODMAS.

Arithmetic operators:

There are different types of arithmetic operators are present in C language. The main operators are division (/), multiplication (*), addition (+) and subtraction (-). Their priorities are as follows:

*, /, % (same priority) 1st priority

+, – (same priority) 2nd priority

Associtivity rule is from Left to Right.

For example:    3 + 4 – 7 = 7 – 7 = 0.

Here two operators are used. One is addition operator and another is subtraction operator. As both operators belong to the same priority level, so preceding rules are followed from left to right. For this addition operator executes first then subtraction operator executes next.

Programming Example 1:

Here we see an example of arithmetic expression. How divide operator is executed in the expression?

1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include <stdio.h>

int main ()

{

    int  x ;            // declaring a variable.
    x= 3 / 4 ;      // arithmetic expression.
    printf ( «%d», x ) ;

return 0 ;

}

Output:

Explanation:

In this programming example the given arithmetic expression is x= 3 / 4;

In C language, if we perform any operation between two integers, result comes as an integer.  Here 3 and 4 both are integers, so the result has not come up with any actual number. So, it cannot come and float number.

So, 11/5= 2, then result will come 2. If x =3.0/4, the result will come 0.75. It means, if a data type will be actual, then result will come in float.

So,

1
2
3
4
5
6
7

3/4 = 0;

3.0/4 = 0.75;

3/4.0 = 0.75;

3.0/4.0 = 0.75;

It means integer will come if and only if both are integer. Otherwise, it will come any actual number.

% operator gives the result of Remainder.

1
2
3
4
5

x = 23%4 = 3

x= 25%5 = 0

x= 3%4 = 3

If we want to divide any number to another number, means it is divisible or not, then use only modulo (%) operator.

Programming Example 2:

Here we see an example of arithmetic expression. How addition operator is executed in the expression?

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <stdio.h>

int main ()

{

    int  x  ;
    x = 3 + 4 ;
    printf ( «%d n « , x ) ;
    return 0 ;

}

Output:

Explanation:

In this programming example the given expression is x = 3 + 4;

Here two operators are used. One is addition operator and another is assignment operator. As addition operator has the higher priority than assignment operator, addition operator executes first, then assignment operator executes. So the addition of 3 and 4 is 7, then 7 is assigned in the variable x with the help of assignment operator.

Programming Example 3:

Here we see an example of arithmetic expression or how subtraction operator is executed in the expression:

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <stdio.h>

int main ()

{

    int  x ;                // declaring a variable.
    x = 34 ;           // arithmetic expression is used.
    printf ( » %d n «, x ) ;
    return 0 ;

}

Output:

Explanation:

In this programming example the given expression is x = 3 – 4;

Here two operators are used. One is subtraction operator and another is assignment operator. As subtraction operator has the higher priority than assignment operator, subtraction operator executes first, then assignment operator executes. So the subtraction of 3 and 4 is -1, then -1 is assigned in the variable x with the help of assignment operator.

Programming Example 4:

Here we see an example of arithmetic expression. How multiplication operator is executed in the expression?

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <stdio.h>

int main ()

{

    int  x ;            // declaring a variable.
    x = 3 * 4 ;     // arithmetic expression is used.
    printf ( » %d n «, x ) ;
    return 0 ;

}

Output:

Explanation:

In this programming example the given expression is x = 3 * 4;

Here two operators are used. One is multiplication operator and another is assignment operator. As multiplication operator has the higher priority than assignment operator, multiplication operator executes first, then assignment operator executes. So the multiplication of 3 and 4 is 12, then 12 is assigned in the variable x with the help of assignment operator.

Programming Example 5:

Here we see an example of arithmetic expression. How different arithmetic operators are executed in the expression?

1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include <stdio.h>

int main ()

{

    int  x= 0 ;
    x = 34 + 2115 *3 / 4 ;
    printf ( » The value of expression is: %d n «, x ) ;

return 0 ;

}

Output:

Explanation:

In this programming example the given expression is x = 34 + 21 – 15 *3 / 4;

Here all arithmetic operators are used.  As the addition, subtraction, division and multiplication operators are used in the given expression, higher priority operator executes first, and then other operator executes. So, multiplication and division operator execute first. After that addition and subtraction operators execute as they belong to the less priority level.

Conclusion:

From the above discussion of arithmetic operator in operator groups, we have come to this conclusion that arithmetic operator is one of the most important operator to operator different types of mathematical data. Through arithmetic operator we can easily solve different types of mathematical operation.



Source link


Decision-making expressions are those which let programmers choose which statement to execute under different circumstances. Conditional statements are used in different programming languages to inform the computer on what factors to make when certain conditions are met. These decisions are taken only if the already stated conditions are true or false: it depends on the functions in the mind of the programmer. The if statement, if-else statement, and if-else-if statements are often used in Dart to introduce the conditional implementation of statements based on one or more Boolean expressions.

The syntax within the example of the Dart If statement, If-Else statement, If-Else-If ladder, and nested If-Else statement will be covered in this tutorial.

How to use the conditionals in the dart in Ubuntu 20.04?

We have demonstrated the representation and implementation of the If statement, If-Else statement, If-Else-If ladder, and nested If-Else statement in the following dart examples.

Example # 1: Using the if condition in a dart in Ubuntu 20.04:

The if statement simply searches the condition and executes the statements inside it if it is true; otherwise, the statements are ignored in the code.

This example starts with the main function where we have implemented if conditional statement. First, we have defined a variable “myNumber” which has the integer value stored in it. After that this variable is utilized inside the if condition. The if has the condition that the variable “number” should be greater than the number “20”. As we have the number “30” greater than the number “20” so the if block returns a print statement. If in case our condition becomes false, then nothing will be executed.

The true statement of if-condition is executed as follows:

Example # 2: Using the if-else condition in a dart in Ubuntu 20.04:

This type of statement checks the condition and executes the statements contained within if it is true; otherwise, the statements contained within else are executed.

If the Boolean expression inside the “if” is true, the script inside the if block is executed, and further execution proceeds with the conditions next to the if-else block.

If the Boolean expression next to the if keyword returns false, the script inside the else block is executed, and the statements next to the if-else block are executed.

In the above dart script, we have first defined the main function. The main function has the integer type variable declared as a “number” to which we have assigned a numeric value. Through the print statement, we have displayed the number inside the variable. Then, we have the if-else representation. The if has the condition given that the variable “number” should be greater than “20”. Inside the if block, the print statement will be executed upon the condition that returns a true value. If the condition returns a false value, then else block will be executed and the if block will be ignored.

As the variable “number” has the value “15” which is not greater than the number inside the if the condition is “20” so the if condition becomes false here. Hence, the else block is executed as follows.

Example # 3: Using the if-else-if ladder condition in a dart in Ubuntu 20.04:

If-Else-If ladders can have a ladder of else-if blocks, but only if a block is required which is at the start and one else block at the optional end.

The Boolean expressions are checked one by one during the execution. If the Boolean condition is true, the associated block of statements is executed; otherwise, the program control moves to the next Boolean in the ladder to be evaluated. The else block is executed if either of the Boolean evaluates is true.

The program has the main function definition where at the initial step, we have constructed a variable as “numeric_val” with the data type “int”. Then, we have the ladder of the if-else statement. The first statement is the if-statement where the condition is defined as the numeric_val Ilesser than the number “5”. If that condition is true, then our first if-condition is executed. Similarly, it considers the second if condition. If it is true, it executes the statements within its block and moves control to the next statement; otherwise, it checks another if condition. Finally, if no if-condition evaluates to true, the statements within the else block are executed and control is passed to the next statement.

From the above if-else ladder, condition2 is true so the if-condition block is executed on the shell of Ubuntu as follows:

Example # 4: Using the nested if-else condition in a dart in Ubuntu 20.04:

In this dart script, we have the variable “Age” of int data type and the variable contains the integer value within the dart main function. Then, we have the if expression, and the if expression is passed with the condition that “age” should be greater than the number “20”. Inside the if block we have first incremented the variable “Age” and then defined the if-else condition within the existing if expression. If the true results are returned from the nested if expression, then the if statement is executed, otherwise the else block is created for the false returned results. If the main if-condition results are false, then the nested if the condition is ignored and nothing will be executed from the above dart script.

As our main if-expression has the true results so the condition is entered into the if-condition block where we have if-else expressions. Inside the if expression our condition fails so the else is executed in the below shell.

Conclusion:

Coding without conditionals forces you to think outside the box. You will have to find new ways to frame your code to try and make it more understandable. It can also assist you in gaining knowledge about computation and/or object-oriented approaches. We have driven all the conditional exists in the dart programming language with the example. We are hoping that there will be no uncertainty with the dart conditionals.



Source link


An interface in the Dart programming language is considered as a way of creating abstraction within your code. The Dart interface acts as a blueprint for all the classes that wish to implement this interface. Afterwards, these classes are required to provide their own implementations for all the interface methods. In this article, we will teach you the use of the interfaces in the Dart programming language in Ubuntu 20.04.

Main Properties of the Interfaces in the Dart:

Following are the main properties of the interfaces in the Dart programming language:

  • There is no direct method of declaring an interface in Dart. However, the simple class declaration can serve as a means of declaring a Dart interface.
  • A Dart class can implement multiple interfaces at a time.
  • The usage of the interfaces in the Dart programming language can help us in achieving multiple inheritances.

How to use the Interfaces in the Dart in Ubuntu 20.04?

To learn the usage of the interfaces in the Dart programming language, you will have to understand the examples explained below:

Example # 1: A Dart Class Implementing another Dart Class:

Since we know that the Dart programming language does not have a direct way of declaring the interfaces, therefore, in this example, we will be creating a class that implements another class to mimic the functionality of an interface. The following Dart script has been written in this regard:

In this Dart script, we have defined a class named “Organization” which will act as an interface. This class has a single member function named “orgName()”. It will not return any value nor will it accept any input parameters. However, this function only has a “print” statement inside it. After designing this class, we have defined another class named “Employee” that implements the “Organization” class. It means that the “Employee” class must implement all the methods of the “Organization” class along with the rest of its functionality.

Inside the “Employee” class, we have declared a member variable named “empName” that refers to the name of the employee. Then, we have a function named “empInfo()” that is used to print the name of the employee on the console. After that, we have implemented the interface method “orgName()” within the “Employee” class. Then, inside our “main()” function, we have created an instance of the “Employee” class named “E1” and have initialized its “empName” variable by using this instance. Finally, we have called both the methods of this class or its own member function as well as the method of the interface implemented within this class by using its object.

To execute this Dart script, we have used the command given below:

$ dart run interfaces.dart

The output of our first example Dart script is shown in the following image. The most important thing to be noticed in this output is that the message defined in the “orgName()” function of the “Employee” class has been printed on the terminal instead of the present inside the interface class. It means that the “Employee” class has successfully implemented the interface class or the “Organization” class.

Example # 2: The Missing Implementation of the Interface Method in a Dart Class:

This example is just a slightly modified version of our first example. Through this example, we want to teach you what happens when you skip the implementation of any of the interface methods inside the class implementing this interface. To do this, we have used the same Dart script that we have designed for the example above. However, this time, we have commented out the implementation of the “orgName()” function within the “Employee” class as shown in the image below:

The rest of the script is intact. After making this modification, when we tried to execute our Dart script, we received the runtime error shown in the following image:

This error message explicitly states that we have skipped the implantation of an interface method within a class that implements this interface. It means that we cannot execute this Dart script unless we provide an implementation of this interface method within the class that implements this interface. Therefore, it is mandatory to provide the implementations of all the interface methods inside the class that implements a specific interface.

Example # 3: Implementing Multiple Interfaces within a Single Dart Class:

The concept of using the interface in the Dart programming language can also be extended to multiple interfaces. A Dart class can easily implement multiple interfaces at a time. The Dart script shown in the image below has been written to demonstrate this:

In this example, we have defined two interfaces in Dart: Organization and Manager whereas the class “Employee” implements both of these interfaces. The “Organization” class has only one member function named “orgName()”. Similarly, the “Manager” class also has only one member function named “designation()”. The “Employee” class that implements these two interfaces has its own member variable and a member function.

Apart from this, it also implements the two methods of the interfaces “Organization” and “Manager”. Then, in the “main()” function, we have just created an object of the “Employee” class and have accessed all of its member variables and functions with this object.

The output of this Dart script is displayed in the following image. It implies that we have successfully implemented multiple interfaces while using the Dart programming language in Ubuntu 20.04.

Conclusion:

With the help of this tutorial, we wanted to explain to you the usage of the interfaces in the Dart programming language. We first began with a brief introduction to the interfaces in Dart followed by a few main properties that are associated with the Dart interfaces. After that, we shared with you three different examples that implemented the Dart interfaces. By going through these examples, you will quickly be able to understand the usage of the interfaces in Dart.



Source link


A set in the Dart programming language is defined as a collection of multiple elements of the same data type. However, each of these elements needs to be unique. In this guide, we will study the usage of the Dart sets in Ubuntu 20.04 by going through some simple yet helpful examples.

Using the Sets in the Dart Programming Language in Ubuntu 20.04:

We have implemented the following seven examples with you to teach you the uses of the sets in the Dart programming language. Each of these examples will introduce you to a new concept associated with the usage of the sets in the Dart programming language.

Example # 1: Declaring a Set by using the Variable Notation in the Dart Programming Language:

There are two different ways of declaring a set in the Dart programming language. We will share with you the first method of doing so. For that, you will have to go through the Dart script shown in the image below:

We have first declared a set named “months” within our “main()” function by making use of the variable notation by using the “var” keyword. This is a “String” type set and contains six different months as its elements. Then, we have just used the “print” statement for printing these elements on the terminal.

To run this Dart script, we have used the following command:

All the elements of our Dart set are shown in the image below:

Example # 2: Declaring a Set by using the Set Notation in the Dart Programming Language:

In this example, we will be sharing with you the second notation for declaring a set in the Dart programming language. For that, you will have to take a look at the following Dart script:

In this Dart script, we have declared the same set of “months” that we have used in the first example. However, this time, we have declared it by using the “set” notation by making use of the “Set” keyword. After declaring and initializing this set, we have just printed its elements on the console.

Upon executing this Dart script, all the elements of our “months” set appeared on the terminal as shown in the image below:

Example # 3: A Set Containing Duplicate Elements in the Dart Programming Language:

Now, when you have learned the two different declarations of the sets in the Dart programming language, we will try to move a step further. We will teach you what happens if you have duplicate elements within a Dart set. For that, you will have to consider the following Dart script:

In this example, we have declared the “months” set in the Dart programming language. However, this time, it contains two duplicate values (i.e. March and September.) To check what happens to this set because of the existence of these duplicate values, we have used a “print” statement for printing the elements of this set on the console.

The output of this Dart script is shown in the image below which tells us that all the duplicate elements present within a Dart set are printed only merienda.

Example # 4: Adding an Element to a Set in the Dart Programming Language:

In this example, we will teach you how you can add an element to an existing set in the Dart programming language. For that, you need to look at the following Dart script:

In this script, we have used the same “months” set that we have used in the examples above. However, this time, we have added a new element to this set by using the “months.add(“May”)” statement. After this modification, we have printed the elements of this set on the terminal again.

The output of this Dart script is shown in the image below. This Dart script has correctly printed the elements of the set after adding a new element to it. Moreover, all the newly added elements to a set are always inserted at the end.

Example # 5: Removing an Element from a Set in the Dart Programming Language:

You can also remove a particular element from a Dart set at any time you want.

In this example, we have just used the “months.remove(“January”)” statement for removing the month “January” from our set. For verifying this removal, we have printed the updated elements of the set on the terminal.

The output of this Dart program is shown in the image below that confirms that our specified element has been successfully removed from our set.

Example # 6: Checking the Length of a Set in the Dart Programming Language:

You can also check the length of a Dart set by making use of the Dart script that follows:

In this Dart program, we have just used the “${months.length}” notation for printing the length of the Dart set on the terminal.

The length of our Dart set in this particular example is “4” as shown in the image below:

Example # 7: Accessing a Particular Index of a Set in the Dart Programming Language:

If you wish to access any particular element or index of a Dart set, then you will have to proceed as explained in the following Dart script:

In this example, we wanted to access the element at the 0th index of our set for which we have simply used the “${months.elementAt(0)}” notation. You can replace “0” with any other index of your choice depending upon the index of the set that you wish to access.

The element present at the 0th index of our set is shown in the image below:

Conclusion:

This article was written to demonstrate the usage of the Dart sets in Ubuntu 20.04. We tried to explain this concept to you with the help of seven simple examples. After going through these examples, you will not only get ordinario with the declaration of the Dart sets but you will also be able to manipulate them by making use of the different associated functions.



Source link


In DMA, the decision on memories that are allocated cannot take during the compile time. This decision or memory is allocated during the Runtime.

Whenever we create any variable through DMA, that type of variables do not have any name; we access these variables through address or pointer.

In SMA, Programmer knows from earlier time that how many Variables or How many memories are required for his/her program.

But In DMA,  programmer does not know from earlier state that how many variables or memory is required, it depends upon the user’s requirement.

Types of DMA:

  1. malloc ()
  2. calloc ()
  3. realloc ()
  4. Free ()

malloc ()

malloc () function is an action statement when compiler read this line. Compiler doesn’t understand how many memories is allocated as it is an action statement. In runtime memory block is created.

Whenever we call malloc () we pass a number as an argument, which it can understand the number of bytes of memory block are to be created by the malloc (). In malloc (), it can’t declare any data type. Malloc () always return the address, which memory block is created.

Malloc () return type is a void pointer because it doesn’t know which types of address it returns. For this we have to type caste.

Here we type caste, because malloc () is a void pointer.

Example-1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#include<stdio.h>

#include<stdlib.h>

#define NULL 0

int main ()
{
    int *a , *t ;
    int size ;
    printf ( » what is the size of the table ? « ) ;
    scanf(«%d»,&size);
    printf ( » n « ) ;
    if ( ( t = ( int* ) malloc ( size * sizeof ( int ) ) )  == NULL )
    {
    printf( » No space available n « ) ;
    exit ( 1 ) ;
    }
    printf ( » n Address of the first byte is %un « , t ) ;
    /* Reading table values*/
    printf ( » n Input table values n « ) ;
    for ( a = t ; a < t + size ; a++ )
    scanf(«%d», a);
    /* Printing table values in reverse order*/
    for ( a = t + size 1 ; a >= t ; a )
    printf ( » %d is stored at address %u n «, *a , a ) ;
    free ( t ) ;
    return 0 ;

Output:

Calloc ():

With the help of calloc () we can create more than one block or array in calloc (we pass two arguments; 1st one is how many blocks we want to create & 2nd one is the size of the block). calloc () also return address in each block by default 0 is exist.

Example-2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include<stdio.h>

#include<stdlib.h>

int main ()
{
    int *n , *freq , i , size ;
    printf ( » what is the size of the list ? « ) ;
    scanf(«%d»,&size);
    n = ( int* ) malloc ( size * sizeof( int ) ) ;
    printf ( » Enter the numbers: « ) ;
    for ( i = 0 ; i < size ; i++ )
    {
        printf ( » n enter the num[%d]: «,i ) ;
        scanf(«%d»,&n[i]);
        if ( n [ i ] < 0 || n [ i ] > 4 )
            {
                printf ( » n Number should be within range (0-4) « ) ;
                i ;
                continue ;
            }
    }
    freq = ( int * ) calloc ( 5 , sizeof ( int ) ) ;
    for ( i = 0 ; i < size ; i++ )
            freq [ n [ i ] ]++ ;
    printf ( » n The frequencies of the numbers are: « ) ;
    for ( i = 0 ; i < 5 ; i++ )
            printf ( » n freq [%d] = %d « , i , freq [ i ] ) ;
    printf ( » n « ) ;
    free ( freq ) ;
    return 0 ;
}

Output:

realloc ()

Whenever we create a block with the help of malloc () or calloc () & we want to change or resize the block, we use realloc ().

1

Void *realloc (void *block, int size)

In realloc() we have to pass the address as an argument from which block we want to resize.

and the size of the block we want to resize. That size we have to pass an argument in realloc ().

Only those blocks which are created by malloc () or calloc () can be resized by realloc ().

Example-3:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define NULL 0

int main()

{

char *buffer ;

/* Allocating memory */

if ( ( buffer = ( char * ) malloc ( 10 ) ) == NULL )

{

printf (» malloc failed. n « ) ;

exit ( 1 ) ;

}

printf ( » Buffer of size %d created n « , sizeof (buffer) );

strcpy ( buffer , » HYDERABAD « ) ;

printf( » n Buffer contains: %s n « , buffer ) ;

/* Reallocation */

if ( ( buffer = ( char * ) realloc ( buffer , 15 ) ) == NULL )

{

printf ( » Reallocation failed. n « ) ;

exit ( 1 ) ;

}

printf ( » n Buffer size modified. n « ) ;

printf ( » n Buffer still contains: %s n « , buffer ) ;

strcpy ( buffer , » SECUNDERABAD « ) ;

printf ( » n Buffer now contains: %s n « , buffer ) ;

/* Freeing memory */

free ( buffer ) ;

return 0 ;

}

Output:

free ()

With the help of free (), we release the memory block that is created by malloc () or calloc () or realloc ().

Static variables only exist into the scope of the block or a function. If we cannot run the free (), whenever static variable p is destroyed, the variable which is created dynamically, that are not destroyed, but stayed forever in RAM or in memory. This is called memory leak. For this free () is required to destroy the memory block that is created dynamically.

Free () only destroy those memory that is created dynamically.

Conclusion:

DMA is a powerful concept in C language because it removes the drawback of SMA. In SMA we have to make decision before running the program that how many memory blocks are created. As a result, memory is wasted or memory is not enough. DMA resolve the problem by taking decision on run time that how many block are required to allocate memory. It allocates memory to the requirement of the program.



Source link


This article will help you understand various methods we can use to search for a string in a Pandas DataFrame.

Pandas Contains Method

Pandas provide us with a contains() function that allows searching if a substring is contained in a Pandas series or DataFrame.

The function accepts a textual string or a regular expression pattern which is then matched against the existing data.

The function syntax is as shown:

1

Series.str.contains(pattern, case=True, flags=0, na=None, regex=True)

The function parameters are expressed as shown:

  1. pattern – refers to the character sequence or regex pattern to search.
  2. case – specifies if the function should obey case sensitivity.
  3. flags – specifies the flags to pass to the RegEx module.
  4. na – fills the missing values.
  5. regex – if True, treats the input pattern as a regular expression.

Return Value

The function returns a series or index of Boolean values indicating if the pattern/substring is found in the DataFrame or series.

Example

Suppose we have a sample DataFrame shown below:

1
2
3
4
5

# import pandas
import pandas as pd

df = pd.DataFrame({«full_names»: [‘Irene Coleman’, ‘Maggie Hoffman’, ‘Lisa Crawford’, ‘Willow Dennis’,‘Emmett Shelton’]})
df

Search a String

To search for a string, we can pass the substring as the pattern parameter as shown:

1

print(df.full_names.str.contains(‘Shelton’))

The code above checks if the string ‘Shelton’ is contained in the full_names columns of the DataFrame.

This should return a series of Boolean values indicating whether the string is located in each row of the specified column.

An example is as shown:

To get the contemporáneo value, you can pass the result of the contains() method as the index of the dataframe.

1

print(df[df.full_names.str.contains(‘Shelton’)])

The above should return:

1
2

full_names
4  Emmett Shelton

Case Sensitive Search

If case sensitivity is important in your search, you can set the case parameter to True as shown:

1

print(df.full_names.str.contains(‘shelton’, case=True))

In the example above, we set the case parameter to True, enabling a case-sensitive search.

Since we search for the lowercase string ‘shelton,’ the function should ignore the uppercase match and return false.

RegEx search

We can also search using a regular expression pattern. A simple example is as shown:

1

print(df.full_names.str.contains(‘wi|em’, case=False, regex=True))

We search for any string matching the patterns ‘ wi’ or ’em’ in the code above. Note that we set the case parameter to false, ignoring case sensitivity.

The code above should return:

Closing

This article covered how to search for a substring in a Pandas DataFrame using the contains() method. Check the docs for more.



Source link


Ly is a free, open-source, minimalistic, and lightweight terminal-based display manager for Linux.

Ly is a great alternative to those who are used to staring at the terminal window all day.

Let us now discuss how to install it on Debian 11.

Update System

The first step is to refresh the repository cache and update the packages. We can do this using the commands:

$ sudo apt-get update
$ sudo apt-get upgrade

Merienda completed, we can proceed with the installation.

Installing Dependencies.

To install ly, we will require a few dependencies. For simplicity, run the command below:

$ sudo apt-get install build-essential libpam0g-dev libxcb-xkb-dev git -y

Installing Ly

The next step is to install the ly display manager. Start by opening your terminal window and clone the repository as shown below:

git clone –recurse-submodules https://github.com/nullgemm/ly.git

Merienda completed, navigate into the directory.

Run the compile command as shown:

Merienda the compilation is complete, run the command below to test the display manager in your current tty session.

If successful, you should see a window as shown:

Press CTRL + C to exit to your terminal window.

The next step is to install Ly and its systemd service. The command is as shown:

Merienda installed, run the command below to enable the systemd service.

$ sudo systemctl enable ly

NOTE: You may need to uninstall your current dm to make this work.

Closing

This short article covers how to install the ly display manager on your Debian 11 installation. Check the docs to learn more.



Source link


Set Objects in JavaScript are very much similar to the arrays the major difference between these two is that the set objects can’t hold the duplicate values however arrays can. In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as object, arrays, literals, etc. In JavaScript several set object methods can be used to achieve different functionalities, for example, add(), delete(), forEach(), etc.

In this article, we will cover the below listed aspects of set object methods in JavaScript:

So, let’s begin!

How to use new Set() to create a set in JavaScript

To work with any of the Set object methods, firstly, we have to create a set. To do so, we can use the “new Set()” constructor.

Example

The below given piece of code will explain how to create a Set in JavaScript using the “new Set()” constructor:

<script>
let employeeNames = new Set();

console.log(employeeNames);
</script>

The above code will create an empty set as shown in the following output:

The output shows that an empty Set is created, now we can perform any functionality on that set using different set object methods such as append elements, remove elements, etc.

How to use add() method to add elements in a set

JavaScript provides a method named add() that is used to append the elements in a set.

Example

Now, we will extend the above example a little bit more to add/append the elements to the Set:

employeeNames.add(«Steve»);
employeeNames.add(«Michael»);
employeeNames.add(«Smith»);
employeeNames.add(«Paul»);
employeeNames.add(«Ambrose»);
console.log(employeeNames);

In this example, we added five elements in the set named “employeeNames” using the add() method. Afterward, we utilized the console.log() method to print all the elements stored in the “employeeNames” set on the browser’s console:

The output verifies the working of the add() method.

How to use delete() method to remove elements from a set

In JavaScript, the delete() method can be used to remove some specific elements from the set object.

Example

Let’s suppose we want to remove “Smith”, and “Paul” from the set “employeeNames”. To do so, we can utilize the delete() method:

employeeNames.delete(«Smith»);
employeeNames.delete(«Paul»);
console.log(employeeNames);

The above code block will generate the following output:

The above snippet shows that the delete() method has removed “Smith” and “Paul” from the Set successfully.

How to use clear() method to delete all elements from a set

In JavaScript, the clear() method can be used to remove all the elements of a set object.

Example

In this example, we will utilize the clear() method to delete all the items from the set “employeeNames”:

employeeNames.clear();
console.log(employeeNames);

The above code snippet will produce the following results:

The output shows the Set’s size equal to zero; it authenticates the working of the clear() method.

How to check the existence of some specific value in a set using has() method

In JavaScript, the has() method can be used to check whether a specific element exists in the set or not.

Example

In this example, we will check the existence of two elements i.e. “Smith”, and “Bryn” using the has() method:

console.log(employeeNames.has(«Smith»));
console.log(employeeNames.has(«bryn»));

The piece of code will return true if the specified value exists in the set and it will return false if the specified value doesn’t exist in the targeted set:

The output shows that the has() method returns true for the element “smith” as it exists in the set while “Bryn” doesn’t exist in the targeted set therefore the has() method returns false for it.

How to find the size of a set

In JavaScript, the size property can be used to check the size/length of some specific set.

Example

In this example we will utilize the size property to check the size of the set “employeeNames”:

Following will be the corresponding output for the above-given code:

The output shows the appropriate size of the specified set i.e “employeeNames” set.

Conclusion

In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as objects, arrays, literals, etc. In JavaScript, there is a wide range of set object methods that can be used to perform different functionalities. For example, Add(), delete(), and clear(), methods are used to append and remove elements, the has() method is used to check the existence of an element in a specific set, etc. This write-up explained the working of various set object methods with the help of suitable examples.



Source link