Linked Lists Explored...

 
Append Node to the List:
    Appending involves add Node to the end of the Linked List , consider doubly linked list provided in the below example code ,

This is the Node looks like :


Code Example:
===========
#include <stdio.h>
#include <stdlib.h>

 
typedef struct sList
{
    char *name;
    struct sList *next_sList;
    struct sList *prev_sList;
} UtilList;


#define MAX_NAME_SIZE 255
/* Generic Operations done in Doubly Linked List - API's */
void utilAppendList(char *name,UtilList **pUtilList);
void utilAddListAtHead(char *name,UtilList **pUtilList);
int  utilRemoveSpecList(UtilList **pUtilList,int listnum2delete);
void utilRemoveList(UtilList **pUtilList);
void utilReverseList(UtilList **pUtilList);
void displayList(UtilList *pUtilList);

/* Other Operations */
void utilSortList(UtilList **pUtilList);
void utilSwapDList(UtilList **pxUtilList,UtilList **pyUtilList);

int main()
{
    char *name[] = {"Test1","Test2","Test3","Test4","Test5"};
    UtilList *pUtilList = NULL;
    /* Add List at Head Node */
    printf("Adding Node at Head Node\n");
    utilAddListAtHead(name[0],&pUtilList);
    utilAddListAtHead(name[1],&pUtilList);
    utilAddListAtHead(name[2],&pUtilList);
    utilAddListAtHead(name[3],&pUtilList);
    utilAddListAtHead(name[4],&pUtilList);
    displayList(pUtilList);
    /* Add List at End */
    printf("Add List at End\n");
    utilAppendList(name[0],&pUtilList);
    utilAppendList(name[1],&pUtilList);
    utilAppendList(name[2],&pUtilList);
    /* Remove a Specified list at given location */
    utilRemoveSpecList(&pUtilList,2);
    utilAppendList(name[3],&pUtilList);
    utilAppendList(name[4],&pUtilList);
    printf("Display list after added both at Head and End\n");
    displayList(pUtilList);
    /* Reversiong List */
    utilRemoveList(&pUtilList);
    printf("After Removing List :\n");
    displayList(pUtilList);
    /* Issues based on appendList */
    return(0);
}

void utilAppendList(char *name,UtilList **pUtilList)
{
    UtilList *ptempUtilList    = (UtilList *)malloc(sizeof(UtilList));
    UtilList *ptempUtilEnd     = NULL;
    if(!(*pUtilList))
    {
        ptempUtilList->name       = (char *)malloc(sizeof(char)* MAX_NAME_SIZE);
        strcpy(ptempUtilList->name,name);
        ptempUtilList->next_sList = NULL;
        ptempUtilList->prev_sList = NULL;
        *pUtilList = ptempUtilList;
    }
    else
    {
        ptempUtilList->name       = (char *)malloc(MAX_NAME_SIZE * sizeof(char));
        ptempUtilEnd              = *pUtilList;
        strcpy(ptempUtilList->name,name);
        while(ptempUtilEnd->next_sList)
        {
            ptempUtilEnd = ptempUtilEnd->next_sList;
        }
        ptempUtilList->prev_sList = ptempUtilEnd;
        ptempUtilList->next_sList = NULL;
        ptempUtilEnd->next_sList  = ptempUtilList;
    }
}

void utilAddListAtHead(char *name,UtilList **pUtilList)
{
    UtilList *ptempUtilList    = (UtilList *)malloc(sizeof(UtilList));
    UtilList *ptempUtilHead    = NULL;
    if(!(*pUtilList))
    {
        ptempUtilList->name       = (char *)malloc(sizeof(char) * MAX_NAME_SIZE);
        strcpy(ptempUtilList->name,name);
        ptempUtilList->next_sList = NULL;
        ptempUtilList->prev_sList = NULL;
        *pUtilList = ptempUtilList;
    }
    else
    {
        ptempUtilList->name       = (char *)malloc(MAX_NAME_SIZE * sizeof(char));
        strcpy(ptempUtilList->name,name);
        (*pUtilList)->prev_sList  = ptempUtilList;
        ptempUtilList->next_sList = *pUtilList;
        *pUtilList = ptempUtilList;
    }
}

void displayList(UtilList *pUtilList)
{
    UtilList *ptempUtilList = pUtilList;
    if(ptempUtilList)
    {
        while(ptempUtilList)
        {
            printf("Name = %s \n",ptempUtilList->name);
            ptempUtilList = ptempUtilList->next_sList;
        }
    }
    else
    {
        printf("List is empty\n");
    }

}

void utilRemoveList(UtilList **pUtilList)
{
    UtilList *pCurrUtilList = NULL;
    while(*pUtilList)
    {
        pCurrUtilList = *pUtilList;
        *pUtilList    = (*pUtilList)->next_sList;
        free(pCurrUtilList->name);
        free(pCurrUtilList);
    }
    *pUtilList = NULL;
}

int utilRemoveSpecList(UtilList **pUtilList,int listnum2delete)
{
    UtilList *pCurrUtilList = *pUtilList;
    int ret                 = 0;
    int count               = 1;

    while((pCurrUtilList) && (count != listnum2delete))
    {
        pCurrUtilList    = pCurrUtilList->next_sList;
        count++;
        ret = 1;
    }
    (*pUtilList)->next_sList = (*pUtilList)->next_sList->next_sList;
    (*pUtilList)->prev_sList = (*pUtilList);
    free(pCurrUtilList->name) ;
    free(pCurrUtilList);
    return ret;
}

void utilSortList(UtilList **pUtilList)
{

}

void utilSwapDList(UtilList **pxUtilList,UtilList **pyUtilList)
{
    UtilList *ptempUtilList = NULL;

}

How to read wav file header in C#

    Reading header information from a wav file is discussed with example code in detail in this blog
(http://www.techband.in/2011/01/how-to-read-wavfile-header-in-c.html).
Here is the C# version of reading header info from a Microsoft specific wav file .

    This class can be used to get  wav header details , show the code below...


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.IO;


namespace wavHeaderParser
{
    class wavHeaderReader
    {

        string FilenameWithPath = "C:\\src\\test.wav";
        byte[] mheader = new byte[4] { 82, 73, 70, 70 }; /* 0 - 4 Bytes */
        UInt32 riffIDSize = 0;          /* 4 - 7 Bytes */
        byte[] wave = new byte[4] { 87, 65, 86, 69 }; /* 8 - 11 Bytes */
        byte[] fmt = new byte[4] { 102, 109, 116, 32 }; /* 12 - 15 Bytes */
        UInt32 Subchunk1Size = 0;
        UInt16 AudioFormat = 0;
        UInt16 NumOfChan = 0;
        UInt32 SamplesPerSec = 0;
        UInt32 bytesPerSec = 0;
        UInt16 blockAlign = 0;
        UInt16 bitsPerSample = 0;
        byte[] Subchunk2ID = new byte[4]{100,97,116,97};
        UInt32 Subchunk2Size = 0;
        byte[] wavHeaderBytes = new byte[44];

        byte[] ReadWavHeaderBytes(string FilenamewithPath)
        {
            const int wavHeaderSizeinBytes = 44;
            byte[] wavHeaderBytes = new byte[wavHeaderSizeinBytes];
            FileStream fs = new FileStream(FilenamewithPath, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            wavHeaderBytes = br.ReadBytes(wavHeaderSizeinBytes);
            return wavHeaderBytes;
        }
        public void getWavHeaderData()
        {
            wavHeaderBytes = ReadWavHeaderBytes(FilenameWithPath);
            Console.WriteLine("----------------------------------------------");
            Console.WriteLine(" WAV Header information:");
            Console.WriteLine("----------------------------------------------");
            if ((wavHeaderBytes[0] == mheader[0]) && (wavHeaderBytes[1] == mheader[1]) && (wavHeaderBytes[2] == mheader[2]) && (wavHeaderBytes[3] == mheader[3]))
            {
                Console.WriteLine(" Magic Header Found : {0}{1}{2}{3} ", (char)wavHeaderBytes[0], (char)wavHeaderBytes[1], (char)wavHeaderBytes[2], (char)wavHeaderBytes[3]);
            }

            riffIDSize = (UInt32)(wavHeaderBytes[7] << 24 | wavHeaderBytes[6] << 16 | wavHeaderBytes[5] << 8 | wavHeaderBytes[4]);
 
            if ((wavHeaderBytes[8] == wave[0]) && (wavHeaderBytes[9] == wave[1]) && (wavHeaderBytes[10] == wave[2]) && (wavHeaderBytes[11] == wave[3]))
            {
                Console.WriteLine(" wave Header Found  : {0}{1}{2}{3} ", (char)wavHeaderBytes[8], (char)wavHeaderBytes[9], (char)wavHeaderBytes[10], (char)wavHeaderBytes[11]);
            }
            if ((wavHeaderBytes[12] == fmt[0]) && (wavHeaderBytes[13] == fmt[1]) && (wavHeaderBytes[14] == fmt[2]) && (wavHeaderBytes[15] == fmt[3]))
            {
                Console.WriteLine(" fmt Header Found   : {0}{1}{2}{3} ", (char)wavHeaderBytes[12], (char)wavHeaderBytes[13], (char)wavHeaderBytes[14], (char)wavHeaderBytes[15]);
            }
            Subchunk1Size = (UInt32)(wavHeaderBytes[19] << 24 | wavHeaderBytes[18] << 16 | wavHeaderBytes[17] << 8 | wavHeaderBytes[16]);
            AudioFormat   = (UInt16)(wavHeaderBytes[21] << 8 | wavHeaderBytes[20]);
            NumOfChan     = (UInt16)(wavHeaderBytes[23] << 8 | wavHeaderBytes[22]);
            SamplesPerSec = (UInt32)(wavHeaderBytes[27] << 24 | wavHeaderBytes[26] << 16 | wavHeaderBytes[25] << 8 | wavHeaderBytes[24]);
            bytesPerSec   = (UInt32)(wavHeaderBytes[31] << 24 | wavHeaderBytes[30] << 16 | wavHeaderBytes[29] << 8 | wavHeaderBytes[28]);
            blockAlign    = (UInt16)(wavHeaderBytes[33] << 8 | wavHeaderBytes[32]);
            bitsPerSample = (UInt16)(wavHeaderBytes[35] << 8 | wavHeaderBytes[34]);
            Console.WriteLine(" RiffIDSize         : {0}",riffIDSize);
            Console.WriteLine(" Subchunk1Size      : {0}",Subchunk1Size);
            Console.WriteLine(" AudioFormat        : {0}",AudioFormat);
            Console.WriteLine(" NumOfChan          : {0}",NumOfChan);
            Console.WriteLine(" SamplesPerSec      : {0}",SamplesPerSec);
            Console.WriteLine(" bytesPerSec        : {0}", bytesPerSec);
            Console.WriteLine(" blockAlign         : {0}", blockAlign);
            Console.WriteLine(" bitsPerSample      : {0}", bitsPerSample);
            if ((wavHeaderBytes[36] == Subchunk2ID[0]) && (wavHeaderBytes[37] == Subchunk2ID[1]) && (wavHeaderBytes[38] == Subchunk2ID[2]) && (wavHeaderBytes[39] == Subchunk2ID[3]))
            {
                Console.WriteLine(" data Header Found  : {0}{1}{2}{3} ", (char)wavHeaderBytes[36],(char)wavHeaderBytes[37],(char)wavHeaderBytes[38],(char)wavHeaderBytes[39]);
            }
            Subchunk2Size = (UInt32)(wavHeaderBytes[43] << 24 | wavHeaderBytes[42] << 16 | wavHeaderBytes[41] << 8 | wavHeaderBytes[40]);
            Console.WriteLine(" Subchunk2Size      : {0}", Subchunk2Size);
            Console.WriteLine("----------------------------------------------");
            Console.ReadLine();
        }

    }
}