Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int read_text(char *text, int text_max_size){
int i;
char x;
int length=0;
scanf("%c", &x);
while(x != '"'){
scanf("%c", &x);
}
for(i=0; i<text_max_size; i++){
scanf("%c", &x);
printf("x: %c\n", x);
if( x == '"'){
break;
}
text[i] = x;
}
return i;
}
void print_text(char *text, int n){
int i;
printf("Text: ");
for(i=0; i<n; i++){
printf("%c", text[i]);
}
printf("\n");
}
/*
void store_text(char *text, int text_size, char **c_array, int n){
int i;
}
*/
int main(void){
int i, k, n;
float root;
char *plaintext, **ch, *ciphertext, *newplaintext;
printf("Please type k (length): ");
scanf("%d", &k);
plaintext = (char *)malloc(k*sizeof(char));
if(plaintext == NULL){
printf("Error in allocating plaintext space.\n");
exit(1);
}
printf("Type the text: ");
k = read_text(plaintext, k);
print_text(plaintext, k);
if(k == 0){
printf("There is no character...");
}
root = sqrt(k);
if((root*2) == k){
n = root;
}else{
n = ((int)root + 1);
}
printf("n: %d\n", n);
ch = (char **)malloc(n*sizeof(char *));
for(i=0; i<n; i++){
ch[i] = (char *)malloc(n*sizeof(char));
}
if(ch == NULL){
printf("Error in allocating ch space.\n");
exit(1);
}
ciphertext = (char *)malloc((n^2)*sizeof(char));
if(ciphertext == NULL){
printf("Error in allocating ciphertext space.\n");
exit(1);
}
newplaintext = (char *)malloc((n^2)*sizeof(char));
if(newplaintext == NULL){
printf("Error in allocating newplaintext space.\n");
exit(1);
}
printf("Encoding in progres.....\n");
//store_text(plaintext, k, ch, n);
return 0;
}
and the output is something like this:
Code:
/tmp/ccWhTnJp.o: In function `main':
ex1.c:(.text+0x1b2): undefined reference to `sqrt'
collect2: ld returned 1 exit status
I know that the wrong part is when calling the sqrt function...but i do not understand why math.h library does not support it...can anyone help? thanks guys...