Author Topic: need some help from someone who knows C (real basic stuff)  (Read 1748 times)

Offline BeefEater

  • Newbie
  • *
  • Posts: 6
    • View Profile
  • Rated:
need some help from someone who knows C (real basic stuff)
« on: December 10, 2004, 12:38:08 PM »
I know at least some of you guys are really into programing. My freind has this program for class. He found the code on the internet and wants to just submit it, but he wants to change it alittle so it doesnt look so plagerized (switch variables and stuff like that) and add comments. The problem is he cant really write C and it has been so long since I have that I dont want to screw it up. If someone more competant than I has a few minutes to fix up this code I would appreciate it. In case your worried about the legality of this all, the code was provided free of an copyright, so the only infringement would be his honor code violation. Thanks in advance, Dave.
**********************************************************

#include
#include
#include
#include
#include
#define MAX 10

struct link
{
int freq;
char ch[MAX];
struct link* right;
struct link* left;
};
typedef struct link node;


void sort(node *[], int);
node* create(char[], int);
void sright(node *[], int);
void Assign_Code(node*, int [], int);
void Delete_Tree(node *);




main()
{
node* ptr;
int i, n, total = 0, u, c[15];
char str[MAX];
node* a[12];
int freq;


printf( "Huffman Algorithm\n");
printf( "Copyright (C) 2003 Pradeep P Chandiramani -PCD-\n" );
printf( "Huffman Algorithm comes with ABSOLUTELY NO WARRANTY;\n");
printf( "This is free software, and you are welcome\n" );
printf( "to redistribute it under GNU GENERAL PUBLIC LICENSE\n" );
printf( "For details read gpl.txt included with installation.\n\n" );

printf( "Press any Key to continue..." );
getch();

printf("\nEnter the number of of variables:");/*input the no. of letters*/
scanf("%d", &n);

for (i = 0; i < n; i++)
{
printf("Enter the variable & probability");/*input the letter & frequency*/
scanf("%s %d", str, &freq);

a = create(str, freq);
}



while (n > 1)
{
sort(a, n);
u = a[0]->freq + a[1]->freq;
strcpy(str,a[0]->ch);
strcat(str,a[1]->ch);
ptr = create(str, u);
ptr->right = a[1];
ptr->left = a[0];
a[0] = ptr;
sright(a, n);
n--;

}
Assign_Code(a[0], c, 0);
getch();




}


node* create(char a[], int x)
{
node* ptr;
ptr = (node *) malloc(sizeof(node));
ptr->freq = x;
strcpy( ptr->ch , a);
ptr->right = ptr->left = NULL;
return(ptr);
}


void sort(node* a[], int n)
{
int i, j;
node* temp;

for (i = 0; i < n - 1; i++)
for (j = i; j < n; j++)
if (a->freq > a[j]->freq)
{
temp = a;
a = a[j];
a[j] = temp;
}
}



void sright(node* a[], int n)
{
int i;
for (i = 1; i < n - 1; i++)
a = a[i + 1];
}


void Assign_Code(node* tree, int c[], int n)
{
int i;
if ((tree->left == NULL) && (tree->right == NULL))
{
printf("%s code:", tree->ch);

for (i = 0; i < n; i++)
{
printf("%d", c);
}
printf("\n");
}
else
{
c[n] = 1;
n++;
Assign_Code(tree->left, c, n);
c[n - 1] = 0;
Assign_Code(tree->right, c, n);
}
}


void Delete_Tree(node * root)
{
if(root!=NULL)
{
Delete_Tree(root->left);
Delete_Tree(root->right);
free(root);
}
}
/* END of NON Graphical Routines*/


/* Start of Graphical Routines*/
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
formally BeefEater[BURP] --> many, many moons ago

Offline BeefEater

  • Newbie
  • *
  • Posts: 6
    • View Profile
  • Rated:
need some help from someone who knows C (real basic stuff)
« Reply #1 on: December 11, 2004, 09:53:40 AM »
disreguard...took care of it
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
formally BeefEater[BURP] --> many, many moons ago

 

El Box de Shoutamente

Last 10 Shouts:

 

Costigan_Q2

September 21, 2024, 07:35:35 AM
Members
Total Members: 2921
Latest: provider

Date Registered : March 20, 2024

*laughs in slow clapping*
 

RyU

September 03, 2024, 05:15:49 PM
And wow Derrick is still playing lol
 

RyU

September 03, 2024, 05:15:15 PM
Just know yesterday is gone and soon tomorrow will be gone too  :)
 

Lejionator

August 08, 2024, 07:28:01 PM
It's tiem to QuakeCon!!!  ;)

https://www.youtube.com/watch?v=ThQd_UJaTys
 

ImperiusDamian

July 26, 2024, 09:34:53 PM
In nomine Quake II et Id Software et Spiritus John Carmack, Amen.
 

QuakeDuke

July 26, 2024, 05:10:30 PM
Hey, shout, summertime blues
Jump up and down in you blue suede shoes
Hey, did you rock and roll? Rock on!!  ...QD
 

Yotematoi

July 24, 2024, 01:31:20 PM
Ayer me mato 5 veces para robarme en la vida real hará lo mismo? [img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid0wXU2VgS7atesBcSoMz5BWMJCJajeZFVT6GzSU6TtpJGddN9kLTvWNgcZaskkbKFQl&amp;show_text=true&amp;width=500
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid0wXU2VgS7atesBcSoMz5BWMJCJajeZFVT6GzSU6TtpJGddN9kLTvWNgcZaskkbKFQl&show_text=true&width=500" width="500"
 

Yotematoi

July 24, 2024, 01:25:59 PM
hi ya está la basura de Martin, se cambió el nombre es un ladron estupido, asi llegó a 10000[img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&amp;show_text
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&show_text
 

Yotematoi

July 24, 2024, 01:25:59 PM
hi ya está la basura de Martin, se cambió el nombre es un ladron estupido, asi llegó a 10000[img]<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&amp;show_text
https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fzoloyoze.torito%2Fposts%2Fpfbid03hZrkDUBJPZKCuFgy5hRUy831ekKJYVRzC7ajXaKQbJ6xcPgKftLukUDfovFyEq3l&show_text

Show 50 latest
Welcome, Guest. Please login or register.
September 22, 2024, 02:31:56 PM

Login with username, password and session length