patterncMinor
toBase64 encoder
Viewed 0 times
tobase64encoderstackoverflow
Problem
My code convert text to Base64. I used the algorithm without bit operations. What do you think about my code?
#include
#include
#define CRT_SECURE_NO_WARNINGS
#define BIN 2
#define MEMORYSIZE 10
void FromSixBitNumbToDec(char *number1, FILE *result){
char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int i = 0;
char out = 0;
int temp_numb = 0;
int resul = 0;
int number = atoi(number1);
int deg = 1;
while (i = 2) { // Divide the number 10 number system on a finite number of the number system and the remnants of the division in the array. If memory is low, it increased by 2 times
numb[i] = number % BIN;
number = number / BIN;
++i; // Array size (numb2 array)
if (i == memory){
numb = (int*)realloc(numb, (BIN * memory) * sizeof(int));
memory *= BIN;
}
}
numb[i] = number; // The last remnant
k = i;
while (k != 7){ // Supplement to the number of 8-bit
k++;
numb[k] = 0;
}
int *numb2 = (int*)calloc(k + 1, sizeof(int)); // Allocates new array for number
memcpy(numb2, numb, (k + 1) * sizeof(int)); // Copy all digits with numb array
free(numb);
for (i = 0; i 0; i--){
fprintf(result, "%c", '=');
}
return;
}
}
printf("\n");
FromSixBitNumbToDec(number, result);
i = 0;
}
fclose(output2);
fclose(result);
}
}
int main(int argc, char *argv[]){
if (1 < argc){
printf("Argument has been Received\n");
toBase64(argv);
} else {
printf("Need some arguments!\nExit... \n");
return 1;
}
return 0;
}Solution
-
You should probably take the filenames as arguments instead of hardcoding them.
-
The code looks very nice horizontally, but is vertically crammed. I would suggest including blank lines between variable declaration blocks and things like if/for/while statements.
-
Some variable names are kinda odd to me. Instead of "temp_numb" just do "temp_number". Instead of "resul" do "temp_result". Truncating words is usually a disaster in terms of readability.
You should probably take the filenames as arguments instead of hardcoding them.
-
The code looks very nice horizontally, but is vertically crammed. I would suggest including blank lines between variable declaration blocks and things like if/for/while statements.
-
Some variable names are kinda odd to me. Instead of "temp_numb" just do "temp_number". Instead of "resul" do "temp_result". Truncating words is usually a disaster in terms of readability.
Context
StackExchange Code Review Q#70667, answer score: 3
Revisions (0)
No revisions yet.