First, I get the string and I find the frequency of the every character. My struct is:
typedef struct huffman_tree{
char c;
int freq; //unsigned?
struct huffman_tree *left; // 0 (left)
struct huffman_tree *right; // 1 (right)
}huffman_tree;
I write this to create Huffman tree...
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
int main(){
int index=1;
int *arr;
int data;
char *c;
FILE *fp;
int input,inp;
arr=(int*)malloc(sizeof(int));
fp=fopen("list2.txt","r")...
#include<stdio.h>
int main(){
char str[]="My first book";
char *a,*b,*c;
sscanf(str,"%s %s %s",a,b,c);
printf("a=%s b=%s c=%s",a,b,c);
}
If I write like this, I am getting seg fault
#include<stdio.h>
int main(){
char str[]="My first book";
char *a,*b,*c;
sscanf("%s %s %s",a,b,c);
printf("a=%s b=%s c=%s",a,b,c);
}
I want the output: a= My b=first and c=book. But it does not work, why?
I want to write code walk around the array recursively. For some reason I cannot share my code. Let's say I have a array like this: arr[4], I want to look 012 123 013 or 01 12 23 02 03 13. In code I write I can look 012 123 or 01 12 23 but I cannot look 013 or 02 03 13. What algorithm should I...
I wirte code but it does not work. I entered n=5 and r=2, result is 0. And I want to calculate this recursively.
#include<stdio.h>
int func(int n, int r);
int main(){
int n,r;
int result=0;
printf("Enter the number:\n");
scanf("%d",&n);
printf("Enter the 2.number:\n")...
at first I added another value that holds the number in the function like this;
#include<stdio.h>
#include<math.h>
double foo(int n, double mean, int n2){
if(n==1){
return(1);
}
if(n!=0){
return( (sqrt((n-mean)*(n-mean))+foo(n-1,mean,n2))/(sqrt(n2-1)) );
}...
return( sqrt((n))+foo(n-1) );
I write like this and it works. Now I'm wondering where I would write the (n) if I wanted to calculate it sqrt((5+4+3+2+1)/n) recursively.
double foo(int arr[], double *ave, int index){
double *s;
*s=*ave;
// calculation//
return(foo (arr,ave,index));
// other calculation//
}
I want to keep the ave value during the recursion, because after ave is calculated, I will do another calculation is recursively in this...
Hello!
My homework is making a crossword.
I write a code like this:
do{
//code
printf("Please enter the coordinate and the word: \n");
scanf(" %c%d %s",&row2,&column2,word2);
if(row2=='E' && word2=="xit") exit(0);
//code
}while(count2!=10);
But this is...