weixin_29117817 2021-05-29 00:34 采纳率: 50%
浏览 469
已采纳

出现 “已触发了一个断点” 情况

#include <stdlib.h>
#include<math.h>
int* decode(int* encoded, int encodedSize, int first, int* returnSize)
{
    int i = 1;
    int count = encodedSize + 1;
    int* ret = returnSize;
    returnSize[0]= first;
      // returnSize++;

      while (i<count)
      {
          returnSize[i] = abs((returnSize[i-1] - encoded[i-1]));
          i++;
      }
    return ret;
}

int main()
{
    int encoded[] = { 1, 2, 3 };
    int first = 1;
    int encodedSize = sizeof(encoded) / sizeof(encoded[0]);
    int count = encodedSize + 1;
    int * returnSize = (int *)malloc(sizeof(char) * (count));
    returnSize=decode(encoded, encodedSize, first, returnSize);
    if (returnSize == NULL)
    {
        exit(0);
    }
    for(int i = 0; i < count; i++)
        printf("%d ", returnSize[i]);
    
    free(returnSize);
    return 0;
}

 

  • 写回答

1条回答 默认 最新

  • qfl_sdu 2021-05-29 01:15
    关注

    int * returnSize = (int *)malloc(sizeof(char) * (count));这句话有问题,你申请的是int*,但是用的是sizeof(char),这是错误的,应该是:

    int * returnSize = (int *)malloc(sizeof(int) * (count));

    如有帮助,请采纳一下,谢谢。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题