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';
通常,在
JOIN
和IN
之间切换时,需要注意重复。 所以一般的解决方案是: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
andIN
, 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 inuser
.
相关问答
更多-
嵌套SELECT与INNER JOIN(Nested SELECT vs INNER JOIN)[2023-12-05]
尝试这个: 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 ...
-
如何使用
选择嵌套元素(How to select nested elements with [2023-01-14]) 这不是内容标记实现中的错误,这确实是它的工作原理。 正如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 = ( ...
-
如何使用嵌套选择(How to use nested select)[2023-08-09]
这是另一个可能更符合您期望结果的答案。 请注意,您需要放置三(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_ ... -
嵌套的SELECT语句(Nested SELECT Statement)[2023-06-22]
我不确定我是否理解这个问题,如果结果对于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(Replacing nested SELECT)[2023-11-05]
对于您的特定情况,这应该工作: 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 ( ...