简体   繁体   English

从指针转换为不同大小的 integer [-Wpointer-to-int-cast]

[英]cast from pointer to integer of different size [-Wpointer-to-int-cast]

I keep getting these warnings我不断收到这些警告

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)我想在 (Mo) 中计算 colors 中的图像大小,在 (Ko) 中计算黑白图像大小,因此为此我使用了终端命令中过去的参数(图像长度和宽度)

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;
}

To convert a char* to an int in C, you don't cast the pointer.要将char*转换为 C 中的int ,您不需要转换指针。 Instead you use atoi .相反,你使用atoi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM