Doubley Linked List.

#include <stdio.h>
#include <stdlib.h>

typedef struct
Node
{
    int data;
    struct Node *next;
    struct Node *prev;
}node;

void insert(node *pointer, int data);
int find(node *pointer, int key);
void delete(node *pointer, int data);
void print(node *pointer);

int
main(void)
{
    node *start, *temp;
    start = (node *)malloc(sizeof(node));
    temp = start;
    temp -> next = NULL;
    temp -> prev = NULL;

    printf("1. Insert\n");
    printf("2. Delete\n");
    printf("3. Print\n");
    printf("4. find\n");
    printf("5. Exit.\n");
    printf("===========\n");

    while (1)
    {
        int query;
        printf("Choose: ");
        scanf("%d", &query);

        if (query == 1)
        {
            int data;
            printf("Enter data: ");
            scanf("%d", &data);
            insert(start, data);
        }
        else if (query == 2)
        {
            int data;
            printf("Enter data to delete: ");
            scanf("%d", &data);
            delete(start, data);
        }
        else if (query == 3)
        {
            int data;
            printf("\tDoubly Linked List\n");
            print(start -> next);
            printf("\n");
        }
        else if (query == 4)
        {
            int data;
            printf("Enter data to find: ");
            scanf("%d", &data);
            int stat = find(start, data);

            if (stat)
            {
                printf("Element found\n");
            }
            else
            {
                printf("Element not found\n");
            }
        }
        else
        {
            exit(0);
        }
    }
    return 0;
}
void
insert(node *pointer, int data)
{
    while ((pointer -> next) != NULL)
    {
        pointer = pointer -> next;
    }

    pointer -> next = (node *)malloc(sizeof(node));
    (pointer -> next) -> prev = pointer;
    pointer = pointer -> next;
    pointer -> data = data;
    pointer -> next = NULL;
}

int
find(node *pointer, int key)
{
    pointer = pointer -> next;

    while (pointer != NULL)
    {
        if ((pointer -> data) == key)
        {
            return 1;
        }

        pointer = pointer -> next;
    }

    return 0;
}

void
delete(node *pointer, int data)
{
    while ((pointer -> next) != NULL &&\
            ((pointer -> next) -> data) != data)
    {
        pointer = pointer -> next;
    }

    if ((pointer -> next) == NULL)
    {
        printf("Element %d not in list\n", data);
    }

    node *temp;
    temp = pointer -> next;
    pointer -> next = temp -> next;
    temp -> prev = pointer;
    free(temp);
}

void
print(node *pointer)
{
    if (pointer == NULL)
    {
        printf("NULL");
        return;
    }

    printf("%d <---> ", pointer -> data);
    print(pointer -> next);
}

Double-Linked-List

Singly Linked List.

#include <stdio.h>
#include <stdlib.h>

typedef struct
Node
{
    int data;
    struct Node *next;
}node;

void insert(node *pointer, int);
int find(node *pointer, int);
void delete(node *pointer, int);
void print(node *pointer);

int
main(void)
{
    node *start, *temp;
    start = (node *)malloc(sizeof(node));
    temp = start;
    temp -> next = NULL;

    printf("1. Insert\n");
    printf("2. Delete\n");
    printf("3. Print\n");
    printf("4. Find.\n");
    printf("5. Exit.\n");
    printf("==========\n");
    while (1)
    {
        int query;
        printf("Choose: ");
        scanf("%d", &query);

        if (query == 1)
        {
            int data;
            printf("Enter data: ");
            scanf("%d", &data);
            insert(start, data);
        }
        else if (query == 2)
        {
            int data;
            printf("Enter data to delte: ");
            scanf("%d", &data);
            delete(start, data);
        }
        else if (query == 3)
        {
            printf("\tSingle Linked List\n");
            print(start -> next);
            printf("\n");
        }
        else if (query == 4)
        {
            int data;
            printf("Enter data to find: ");
            scanf("%d", &data);
            int stat = find(start, data);

            if (stat)
            {
                printf("Element found\n");
            }
            else
            {
                printf("Element not found\n");
            }
        }
        else
        {
            exit(0);
        }
    }
    return 0;
}

void
insert(node *pointer, int data)
{
    while (pointer -> next != NULL)
    {
        pointer = pointer -> next;
    }

    pointer -> next = (node *)malloc(sizeof(node));
    pointer = pointer -> next;
    pointer -> data = data;
    pointer -> next = NULL;
}

int
find(node *pointer, int key)
{
    while (pointer != NULL)
    {
        if (pointer -> data == key)
        {
            return 1;
        }

        pointer = pointer -> next;
    }

    return 0;
}

void
delete(node *pointer, int data)
{
    while ((pointer -> next) != NULL &&\
            ((pointer -> next) -> data) != data)
    {
        pointer = pointer -> next;
    }

    if (pointer -> next == NULL)
    {
        printf("[!] element %d not in list.\n", data);
    }

    node *temp;
    temp = pointer -> next;
    pointer -> next = temp -> next;
    free(temp);
}

void
print(node *pointer)
{
    if (pointer == NULL)
    {
        printf("NULL");
        return;
    }

    printf("%d ---> ", pointer -> data);
    print(pointer -> next);
}

link1

Client/Server in C.

The Server Side:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <time.h>
#include <string.h>

#define MAX 100

void CService(int);

int
main(void)
{

	int server_sockfd, client_sockfd;
	int server_len;
	unsigned client_len;
	int rc;

	struct sockaddr_in server_address;
	struct sockaddr_in client_address;

	server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (server_sockfd == -1)
	{
		sleep(1);
		printf("[!] Socket Creation Failed !!\n");
		exit(0);
	}
	sleep(1);
	printf("[+] Socket Successfully Created.\n");
	server_address.sin_family = AF_INET;
	server_address.sin_addr.s_addr = htons(INADDR_ANY);
	server_address.sin_port = htons(7734);
	server_len = sizeof(server_address);

	rc = bind(server_sockfd, (struct sockaddr *) &server_address, server_len);
	if (rc != 0)
	{
		sleep(1);
		printf("[!] Socket Binding Failed!!\n");
		exit(0);
	}
	sleep(1);
	printf("[+] Socket Successfully Binded.\n");

	rc = listen(server_sockfd, 5);
	if (rc != 0)
	{
		sleep(1);
		printf("[!] Listen Failed !!\n");
		exit(0);
	}
	sleep(1);
	printf("[+] Server Listening.\n");

	client_len = sizeof(client_address);
	client_sockfd = accept(server_sockfd, (struct sockaddr *) &client_address, &client_len);

	if (client_sockfd < 0)
	{
		sleep(1);
		printf("[!] Server Accept Failed !!\n");
		exit(0);
	}
	sleep(1);
	printf("[+] Server Accept The Client.\n");

	CService(client_sockfd);

	close(client_sockfd);
	return 0;
}

void
CService(int client_sockfd)
{
    char buff[MAX];
    int n = 0;

	for (;;)
	{
		bzero(buff, MAX);
		printf("[!] Server Waiting !!\n");
		read(client_sockfd, buff, sizeof(buff));
		printf("[+] Client Request: %s\n", buff);
		bzero(buff, MAX);

		printf("[+] You: ");
		while ((buff[n++] = getchar()) != '\n');
		{

			if (strncmp(buff, "exit", 4) == 0)
			{
				printf("[!] Server Exit !!\n");
				printf("[!] bye.\n");
				exit(0);
			}

			write(client_sockfd, buff, sizeof(buff));
		}
	}
}

The Client Side:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <time.h>
#include <string.h>

#define MAX 100

void CService(int);

int
main(void)
{
	int sockfd, len, rc;
	struct sockaddr_in address;
	int result;

	sockfd = socket(PF_INET, SOCK_STREAM, 0);
	if (sockfd == -1)
	{
		sleep(1);
		printf("[!] Socket Creation Failed !!\n");
        exit(0);
	}
	sleep(1);
	printf("[+] Socket Successfully Created.\n");

	address.sin_family = AF_INET;
    address.sin_addr.s_addr = inet_addr("127.0.0.1");
    address.sin_port = htons(7734);
    len = sizeof(address);

    result = connect(sockfd, (struct sockaddr *)&address, len);
    if(result != 0)
    {
    	sleep(1);
        printf("[!] Connection With Server Failed !!\n");
        exit(0);
    }
    sleep(1);
    printf("[+] Connected To Server.\n");


    CService(result);

	close(sockfd);
	return 0;
}

void
CService(int sockfd)
{
    char buff[MAX];
    int n;

    for (;;)
    {
    	bzero(buff, MAX);
    	printf("[**] You : ");
    	n = 0;
	    while ((buff[n++] = getchar()) != '\n');
	    {

	        if ((strncmp(buff, "exit", 4)) == 0)
	        {
	        	printf("[!] Client Exit !!\n");
	        	printf("[!] bye.\n");
	        	break;
	        }

	        write(sockfd, buff, sizeof(buff));
	        bzero(buff, MAX);
	        printf("[*] Waiting Response.\n");
	        read(sockfd, buff, sizeof(buff));
	        printf("[+]Response From Server: %s\n", buff);


	    }
	}
}

Screen shots:
This is the server:
Blog-Server
This is the client:
Blog-Client

Simple Socket in c

#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>

/*
 *      && Create a Socket &&
 * Address Family : AF_INET (this is IP version 4)
 * Type : SOCK_STREAM (this means connection oriented TCP protocol)
 * Protocol : 0 [ or IPPROTO_IP This is IP protocol]
 *
 * */

int
main(void)
{
    int sock;
    struct sockaddr_in server;
    char *message, server_rep[2000];
// =====================================================================
    // Create a socket.
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1)
    {
        printf("[-] could not create socket !!\n");
        exit(0);
    }
    else
    {
        printf("[+] ctreated socket.\n");
    }
// =====================================================================
    // set information.
    server.sin_addr.s_addr = inet_addr("74.125.235.20");
    server.sin_family = AF_INET;
    server.sin_port = htons( 80 );
// =====================================================================
    // Connect to remote server.
    /*
     * just for SOCK_STREAM/TCP type of sockets.
     * other socket like UDP , ICMP , ARP dont have connection.
     * */
    if (connect(sock, (struct sockaddr *) & server, sizeof(server)) < 0)
    {
        printf("[!] connection failed !!\n");
        exit(0);
    }
    else
    {
        printf("[+] connected.\n");
    }
// ====================================================================
    // Send some data.
    /*
     * http command to fetch the mainpage of a website.
     * */
    message = "GET / HTTP/1.1\r\n\r\n";
    if (send(sock, message, strlen(message), 0) < 0)
    {
        printf("[1] sending failed !!\n");
        exit(0);
    }
    else
    {
        printf("[+] data send.\n");
    }
// ====================================================================
    // Recieve a replay from the server.
    if (recv(sock, server_rep, 2000, 0) < 0)
    {
        printf("[!] failed to recieve data !!\n");
        exit(0);
    }
    else
    {
        printf("[+] data recieved !!\n");
        printf("%s", server_rep);
    }
    return 0;
}

/*
    <----Just Look at the structure---->
// IPv4 AF_INET sockets:
struct sockaddr_in {
    short            sin_family;   // e.g. AF_INET, AF_INET6
    unsigned short   sin_port;     // e.g. htons(3490)
    struct in_addr   sin_addr;     // see struct in_addr, below
    char             sin_zero[8];  // zero this if you want to
};

struct in_addr {
    unsigned long s_addr;          // load with inet_pton()
};

struct sockaddr {
    unsigned short    sa_family;    // address family, AF_xxx
    char              sa_data[14];  // 14 bytes of protocol address
};
*/

Screen shot from output:
socket

Dynamic memory allocation in C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int
main()
{
    // declare pointer.
    char *memory_alloc;

    // allocate size in memory for variable.
    memory_alloc = malloc(20 * sizeof(char));

    if (memory_alloc == NULL)
    {
        printf("Couldn't allocate request memory !!");
    }
    else
    {
        //
        strcpy(memory_alloc, "IT House!!");
        printf("dynamically allocated memory at %s\n", memory_alloc);
    }
    // frees the allocated memory by malloc.
    // and returns the memory to the system.
    free(memory_alloc);

    // check memory after free func.
    printf("after free is : %s\n", memory_alloc);

    return 0;
}