I want to calculate the image size in colors in (Mo) and in black and white in (Ko) so for this I'm using a parameters that are past in a terminal command which are (image length and width)
Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc, char *argv[]) {
float resultKo, resultMo;
resultKo = ((int)argv[1] * (int)argv[2]) / (1024);
resultMo = (((int)argv[1] * (int)argv[2])/(1024 * 1024))*3;
printf("la taille de l'image en niveau de gris : %.2fko\n",resultKo);
printf("la taille de l'image en couleur : %.2fMo", resultMo);
return 0;
}
CodePudding user response:
To convert a char*
to an int
in C, you don't cast the pointer. Instead you use atoi
.