首页 \ 问答 \ C中矩阵的分段故障(Segmentation fault in matrix in C)

C中矩阵的分段故障(Segmentation fault in matrix in C)

我试图在C中创建一个矩阵并有一些输入值,但我不知道为什么它会给我一个“分段错误”。 这是我的代码:

#include <stdio.h> 
#include <stdlib.h>

int main() {
    int i;
    int j;
    int **a;
    a = malloc(5 * sizeof(int));
    for (i = 0; i < 5; i++) {
      a[i] = malloc(4 * sizeof(int));
    }
    for (i = 0; i < 5; i++) {
      for (j = 0; j < 4; j++) {
        scanf("%d", (a[i][j]));
      }
    }
    return 0;
}

I've tried to create a matrix in C and have some input value, but I don't know why it throws me a "segmentation error". This is my code:

#include <stdio.h> 
#include <stdlib.h>

int main() {
    int i;
    int j;
    int **a;
    a = malloc(5 * sizeof(int));
    for (i = 0; i < 5; i++) {
      a[i] = malloc(4 * sizeof(int));
    }
    for (i = 0; i < 5; i++) {
      for (j = 0; j < 4; j++) {
        scanf("%d", (a[i][j]));
      }
    }
    return 0;
}

原文:
更新时间:2022-03-02 16:03

最满意答案

对于您的特定情况,这应该工作:

SELECT p.event_id, p.user_id
FROM public."point" p JOIN
     public."user" u
     ON p.user_id = u.id 
WHERE u.email = 'test@gmail.com';

通常,在JOININ之间切换时,需要注意重复。 所以一般的解决方案是:

SELECT p.event_id, p.user_id
FROM public."point" p JOIN
     (SELECT DISTINCT u.id
      FROM public."user" u
      WHERE u.email = 'test@gmail.com'
     ) u
     ON p.user_id = u.id ;

id可能在user已经是唯一的。


For your particular case, this should work:

SELECT p.event_id, p.user_id
FROM public."point" p JOIN
     public."user" u
     ON p.user_id = u.id 
WHERE u.email = 'test@gmail.com';

In general, when switching between JOIN and IN, you need to be careful about duplicates. So the general solution would be:

SELECT p.event_id, p.user_id
FROM public."point" p JOIN
     (SELECT DISTINCT u.id
      FROM public."user" u
      WHERE u.email = 'test@gmail.com'
     ) u
     ON p.user_id = u.id ;

But the id is probably already unique in user.

相关问答

更多
  • 尝试这个: latlongs = LatLong.objects.filter(date__gte=time1, date__lte=time2, vehicle__omei=omei) try this: latlongs = LatLong.objects.filter(date__gte=time1, date__lte=time2, vehicle__omei=omei)
  • var foos = from dllFile in Directory.GetFiles(path, "*.dll") from type in Assembly.LoadFrom(dllFile).GetTypes() where !type.IsInterface && typeof(IFoo).IsAssignableFrom(type) select (IFoo) Activator.CreateInstance(type); return foos.ToDict ...
  • 它看起来应该用where子句重写: select iteration, col from tbl where id = 223652 and iteration = (select max(iteration) from tbl where id = 223652); It looks like this should be rewritten with a where clause: select iteration, col from tbl where id = 2236 ...
  • 这不是内容标记实现中的错误,这确实是它的工作原理。 正如HTML5Rocks上关于shadow dom 101的文章所述: 注意:select只能选择主机节点的直接子节点。 也就是说,你不能选择后代(egselect =“table tr”)。 因此,实现的内容选择器仅针对直接子节点,而不是嵌套元素。 This is not a bug in implementation of content tag, this is indeed how it works. As explained here in HT ...
  • 试试这个(关键是使用标量选择 ): pear_table = ( select([PEAR.pear_id]) .where(PEAR.pear_color == 'green') ) apple_min = ( select([func.min(APPLE.apple_date).label('apple_min')]) .where(APPLE.apple_id == pear_table.c.pear_id) ).as_scalar() lemon_max = ( ...
  • 这是另一个可能更符合您期望结果的答案。 请注意,您需要放置三(3)个所需的ID SELECT l1.id AS select_id FROM location l1 WHERE l1.id IN ( SELECT l2.id FROM location l2, location l3 WHERE l2.id = 1 OR l2.parentLocation_id = 1 OR (l2.parentLocation_id = l3.id AND l3.parentLocation_ ...
  • 我不确定我是否理解这个问题,如果结果对于service_contract是可以的,那么你可以收缩服务 SELECT con.ContractId, con.Contract, conSer.Contract_ServiceID, conSer.Service, (SUM(CompletionPercentage)/COUNT(CompletionPercentage)) * 100 as "Percent Complete" FR ...
  • 正如pccardune所说,你会得到像这样的相关用户: friendships = Friendship.objects.filter(from_friend=some_user) 但实际上你可以直接将它传递给你的下一个查询: second_select = Whatever.objects.filter(friend__in=friendships) As pccardune says, you get the relevant users like this: friendships = Frien ...
  • 对于您的特定情况,这应该工作: SELECT p.event_id, p.user_id FROM public."point" p JOIN public."user" u ON p.user_id = u.id WHERE u.email = 'test@gmail.com'; 通常,在JOIN和IN之间切换时,需要注意重复。 所以一般的解决方案是: SELECT p.event_id, p.user_id FROM public."point" p JOIN (SEL ...
  • 当其中一个值为NULL时,通常会发生这种情况。 所以这可能有效: select restname from City.resturant where restid not in (select distinct internal_id from ratingsapp.hotel03 where internal_id is not null); 编写此查询的另一种方法是not exists : select restname from City.resturant r where not exists ( ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)