Welcome,
Guest
. Please
login
or
register
.
November 03, 2025, 01:19:47 PM
News:
tastyspleen.net discord server:
http://discord.tastyspleen.net
Home
Forum
Help
TinyPortal
Search
Calendar
Login
Register
tastyspleen::quake 2 community
»
Forum
»
Quake Related Topics
»
Quake
(Moderator:
[BTF]DeathStalker
) »
need some help from someone who knows C (real basic stuff)
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: need some help from someone who knows C (real basic stuff) (Read 1988 times)
BeefEater
Newbie
Posts: 6
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*/
Logged
formally BeefEater[BURP] --> many, many moons ago
BeefEater
Newbie
Posts: 6
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
Logged
formally BeefEater[BURP] --> many, many moons ago
Print
Pages: [
1
]
Go Up
« previous
next »
tastyspleen::quake 2 community
»
Forum
»
Quake Related Topics
»
Quake
(Moderator:
[BTF]DeathStalker
) »
need some help from someone who knows C (real basic stuff)
El Box de Shoutamente
Last 10 Shouts:
|iR|Focalor
October 31, 2025, 11:40:27 PM
Yotematoi
October 26, 2025, 07:03:58 AM
I've been sick with Q2 since 2007. It's incurable.
Dying and reviving is common. It's a shame the QT was good.
-Unh0ly-
October 11, 2025, 09:33:09 AM
https://drive.google.com/file/d/1PiMmfuFbIkO0NMi9N3nhRrqkLmwQ3JtT/view?usp=sharing
GOOGLE GEMini AI UPSCALED AND REALISTIC game textures ,, unzip to baseq2 obviously
-Unh0ly-
September 23, 2025, 04:27:34 PM
https://drive.google.com/file/d/13RyezOeswNyYytT01Pc878dxRoSXyqYi/view?usp=sharing
QUAKE 2 RTX FULL VERSION
-Unh0ly-
August 09, 2025, 07:31:34 AM
https://youtu.be/ZEVF8_a6kgs
yahoo
July 22, 2025, 11:28:06 PM
https://edition.cnn.com/2025/07/22/entertainment/ozzy-osbourne-death
|iR|Focalor
July 04, 2025, 06:33:05 AM
RyU
June 29, 2025, 06:27:46 PM
Q2 must never die
|iR|Focalor
May 26, 2025, 01:17:30 PM
-Unh0ly-
May 24, 2025, 10:08:35 PM
https://drive.google.com/file/d/1qwsj3EM4s5svp0b8oJLZt_An6990RB-o/view?usp=sharing
QUAKE 2 RTX
Show 50 latest
User
Welcome,
Guest
. Please
login
or
register
.
November 03, 2025, 01:19:47 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search
Advanced search