zoukankan      html  css  js  c++  java
  • 关于User breakpoint called from code at 0x77f9193c的问题

    今日在运行如下程序时出现以上问题:

    #include<stdio.h>
    #include<stdlib.h>
    #define N 3
    int main()
    {
        int arr[N][N]={NULL};
        int *p=NULL;
        int *ConvertFun(int(*)[N]);
        int i,j;
        printf("please input the orginal matrix:
    ");
        for(i=0;i<N;i++)
            for(j=0;j<N;j++)
                scanf("%d",arr[i]+j);
        p=ConvertFun(arr);
        printf("the convert matrix is:
    ");
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
                printf("%d ",*p++);
            printf("
    ");
        }
        free(p);
        return 0;
    }
    
    int *ConvertFun(int(*p)[N])
    {
        int* arr=(int*)malloc(N*N*sizeof(int));
        int i,j;
        for(i=0;i<N;i++)
            for(j=0;j<N;j++)
                *(arr+i*N+j)=p[j][i];
        return arr;
    }

    后来发现堆中的初始地址p由最开始移动到最末尾,free()释放的不再是malloc空间(即存在两个断点,子函数arr的开头及结尾),故需要将*p++改为*(p+i*N+j),那么问题就得到解决。

  • 相关阅读:
    164.Maximum Gap
    163.Missing Ranges
    162.Find Peak Element
    161.One Edit Distance
    160.Intersection of Two Linked Lists
    7.5爬取猫眼Top100电影名单
    7.5文件操作
    7.4文件操作(1)
    7.4一个失败的网易云爬虫,
    7.3数据结构(1)
  • 原文地址:https://www.cnblogs.com/2Bthebest1/p/7103708.html
Copyright © 2011-2022 走看看