Quake3 volumn switch script

//===============
//volume switcher
//===============
seta vol1 "s_volume 0; echo ^2VOLUME 0 ^7|^3---------; set volume_up vstr vol2; set volume_down vstr vol18"
seta vol2 "s_volume .05;echo ^2VOLUME .05 ^2|^3---------; set volume_up vstr vol3; set volume_down vstr vol1"
seta vol3 "s_volume .1; echo ^2VOLUME 1 ^2|^7|^3-------; set volume_up vstr vol4; set volume_down vstr vol2"
seta vol4 "s_volume .2; echo ^2VOLUME 2 ^2||^3-------; set volume_up vstr vol5; set volume_down vstr vol3"
seta vol5 "s_volume .3; echo ^2VOLUME 3 ^2||^7|^3------; set volume_up vstr vol6; set volume_down vstr vol4"
seta vol6 "s_volume .4; echo ^2VOLUME 4 ^2|||^3------; set volume_up vstr vol7; set volume_down vstr vol5"
seta vol7 "s_volume .45;echo ^2VOLUME 4.5 ^2|||^7|^3-----; set volume_up vstr vol8; set volume_down vstr vol6"
seta vol8 "s_volume .5; echo ^2VOLUME 5 ^2||||^3-----; set volume_up vstr vol9; set volume_down vstr vol7"
seta vol9 "s_volume .55;echo ^2VOLUME 5.5 ^2||||^7|^3----; set volume_up vstr vol10; set volume_down vstr vol8"
seta vol10 "s_volume .6; echo ^2VOLUME 6 ^2|||||^3----; set volume_up vstr vol11; set volume_down vstr vol9"
seta vol11 "s_volume .65;echo ^2VOLUME 6.5 ^2|||||^7|^3---; set volume_up vstr vol12; set volume_down vstr vol10"
seta vol12 "s_volume .7; echo ^2VOLUME 7 ^2||||||^3---; set volume_up vstr vol13; set volume_down vstr vol11"
seta vol13 "s_volume .75;echo ^2VOLUME 7.5 ^2||||||^7|^3--; set volume_up vstr vol14; set volume_down vstr vol12"
seta vol14 "s_volume .8; echo ^2VOLUME 8 ^2|||||||^3--; set volume_up vstr vol15; set volume_down vstr vol13"
seta vol15 "s_volume .85;echo ^2VOLUME 8.5 ^2|||||||^1|^3-; set volume_up vstr vol16; set volume_down vstr vol14"
seta vol16 "s_volume .9; echo ^2VOLUME 9 ^2||||||||^3-; set volume_up vstr vol17; set volume_down vstr vol15"
seta vol17 "s_volume .95;echo ^2VOLUME 9.5 ^2|||||||^1|^3; set volume_up vstr vol18; set volume_down vstr vol16"
seta vol18 "s_volume 1; echo ^2VOLUME 10 ^2|||||||^1||^3; set volume_up vstr vol1; set volume_down vstr vol17"
set volume_up vstr vol1

//===============
// Bind them!
//===============
bind = "vstr volume_up"
bind - "vstr volume_down"

A quicksort C demo, with and without radom pivot.

#include 
#include 

void out_int_array(int data[], int n)
{
    int i;
    for(i = 0; i < n; i++)
    {
        printf("%d ", data[i]);
    }
    printf("\n");
}
void swap(int *a, int *b)
{
    int x;
    x = *a;
    *a = *b;
    *b = x;
}

int new_random(int min, int max)
{
    return (min + (int)(((float)rand()/RAND_MAX)*(max - min)));
}
int partition(int A[], int p, int r)
{
    int i = p - 1, j;
    for(j = p; j < r; j++)
    {
        if(A[j] >= A[r])
        {
            i++;
            swap(&A[i], &A[j]);
        }
    }
    swap(&A[i + 1], &A[r]);
    return i + 1;
}

void quicksort(int A[], int p, int r)
{
    int i;
    if(p < r)
    {
        i = partition(A, p, r);
        quicksort(A, 0, i - 1);
        quicksort(A, i + 1, r);
    }   
}

int randomize_partition(int A[], int p, int r)
{
    int i = new_random(p, r);
    swap(&A[i], &A[r]);
    return partition(A, p, r);
}

void randomize_quicksort(int A[], int p, int r)
{
    int i;
    if(p < r)
    {
        i = randomize_partition(A, p, r);
        quicksort(A, 0, i - 1);
        quicksort(A, i + 1, r);
    }   
}

int main()
{
    int A[] = {4, 1, 44, -12, 5, 125, 30};
    int B[] = {4, 1, 44, -12, 5, 125, 30};
    out_int_array(A, 7);
    quicksort(A, 0, 6);
    out_int_array(A, 7);
    printf("--------------------------randomize-----------------------------\n");   
    srand((unsigned)time( NULL ));
    randomize_quicksort(B, 0, 6);
    out_int_array(B, 7);
    return 0;
}

Simple file reader... I'm learning

#include 

#define BUFSIZE 1024

void usage(char *cmd)
{
 printf("Usage: %s \n", cmd);
 printf("If your file is at /home/sudha/documents/names.txt, then the command will be: \n");
 printf("%s /home/sudha/documents/names.txt\n", cmd);
}

int main(int argc, char *argv[])
{
 FILE *fp;

 if (argc < 2)
 {
   usage(argv[0]);
   exit(0);
 }

 fp = fopen(argv[1], "r");
 if (fp == NULL)
 {
   usage(argv[0]);
   exit(0);
 }

 printf("Contents of %s are: \n", argv[1]);

 while (!feof(fp))
 {
   char buf[BUFSIZE] = {0};

   fread(buf, sizeof(char), BUFSIZE, fp);
   printf("%s", buf);
 }

 printf("End of the file\n");

 fclose(fp);
}
| More

Twitter Updates