Monday, December 31, 2012

Which algorithm is efficient for swapping?

Swapping of two numbers/characters can be done by different ways. Generally all people know swapping using a temporary variable. 
In this post i will tell you how to swap two variables in 3 different ways,  and which algorithm is efficient to swap the variables. 

Here all the below examples are shown in C code(executed in linux environment with gcc compiler).

Method 1:
  • Swapping using a temporary variable:

Friday, December 7, 2012

How to write a UDP socket program in Qt


We have seen how to write a simple UDP socket program in C (Linux) in the earlier post..

Now we are going to learn how to write a simple UDP socket program in Qt..

In the following example we used to send and receive data on localhost address.
And the readyRead() signal and slot is used whenever the data receives on the given socket (i.e. socket reday for read data), the control goes to slot method.
writeDatagram() and readDatagram() API's used for sending and receiving data on the given udp socket.

Before starting the Program to write, create a Project using following steps 
  • open Qt creator
  • Create Project
  • Select Other Project in Projects tab then select Qt Console Application, then click on choose...
  • Then give the Project name
  • And then click on Next, Finish in the following dialog boxes
  • Then open the .pro file and write QT += network 
  • To create the cpp file Right click on the project then choose Add new