我几天前刚刚开始学习C,而且我在使用指针时遇到了一些困难.我正在尝试将字符串转换为整数数组.下面的小snipet似乎正在工作,但我收到一个警告:
在函数'charToInt32'警告:赋值从整数生成指针而没有强制转换[默认启用] | || ===构建完成:0个错误,1个警告(0分钟,0秒)=== |
警告来自线路
int32result[pos] = returnedInteger;
Run Code Online (Sandbox Code Playgroud)
所以我试图了解什么是最好的解决方案.我应该使用strncpy(但是我可以使用strncpy作为整数吗?)或其他什么,或者我只是完全误解了指针?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int charToInt32(char * clearText, unsigned int * int32result[])
{
int i = 0, j = 0, pos = 0; /* Counters */
int dec[4] = {24, 16, 8, 0}; /* Byte positions in an array*/
unsigned int returnedInteger = 0; /* so we can change the order*/
for (i=0; clearText[i]; i+=4) {
returnedInteger = 0;
for (j=0; j <= 3 ; j++) { …Run Code Online (Sandbox Code Playgroud)