为什么以下工作?我希望有人会NullPointerException
被扔掉.
String s = null;
s = s + "hello";
System.out.println(s); // prints "nullhello"
Run Code Online (Sandbox Code Playgroud) 我一直在追逐这个bug,我只是不明白.我忘了一些基本的C或什么?
==28357== Conditional jump or move depends on uninitialised value(s)
==28357== at 0x4C261E8: strlen (mc_replace_strmem.c:275)
==28357== by 0x4E9280A: puts (ioputs.c:36)
==28357== by 0x400C21: handlePath (myshell.c:105)
==28357== by 0x400B17: handleInput (myshell.c:69)
==28357== by 0x400AAD: acceptInput (myshell.c:60)
==28357== by 0x4009CF: main (myshell.c:33)
==28357== Uninitialised value was created by a heap allocation
==28357== at 0x4C25153: malloc (vg_replace_malloc.c:195)
==28357== by 0x400BDE: handlePath (myshell.c:99)
==28357== by 0x400B17: handleInput (myshell.c:69)
==28357== by 0x400AAD: acceptInput (myshell.c:60)
==28357== by 0x4009CF: main (myshell.c:33)
==28357==
(095) void handlePath(char *input) { …
Run Code Online (Sandbox Code Playgroud) 我的程序(碰巧在Perl中,虽然我不认为这个问题是Perl特定的)在表单的程序中的某一点输出状态消息,Progress: x/yy
其中x
和yy
是一个数字,如:Progress: 4/38
.
当打印新状态消息时,我想"覆盖"上一个输出,因此我不会在屏幕上显示状态消息.到目前为止,我试过这个:
my $progressString = "Progress\t$counter / " . $total . "\n";
print $progressString;
#do lots of processing, update $counter
my $i = 0;
while ($i < length($progressString)) {
print "\b";
++$i;
}
Run Code Online (Sandbox Code Playgroud)
如果我在其中包含换行符,则不会打印退格符$progressString
.但是,如果我省略换行符,则永远不会刷新输出缓冲区,也不会打印任何内容.
对此有什么好的解决方案?
我有一个表格的元组列表(string, int)
.我正在尝试搜索列表并返回其字符串组件与参数匹配的元组,如:let find_tuple string_name tuples_list =
我怎样才能做到这一点?我无法完全绕过它.有没有办法使用匹配的语法(string, _) ->...
?
将分隔的字符串转换为C(而不是C++)中的字符串数组的有效方法是什么?例如,我可能有:
char *input = "valgrind --leak-check=yes --track-origins=yes ./a.out"
Run Code Online (Sandbox Code Playgroud)
源字符串将始终只有一个空格作为分隔符.我想要一个malloc的malloc'ed字符串数组,char *myarray[]
以便:
myarray[0]=="valgrind"
myarray[1]=="--leak-check=yes"
...
Run Code Online (Sandbox Code Playgroud)
编辑我必须假设有任意数量的令牌,inputString
所以我不能把它限制在10或其他什么.
我已经尝试了一个混乱的解决方案strtok
和我已经实现的链表,但valgrind抱怨太多,我放弃了.
(如果你想知道,这是我想写的基本Unix shell.)
免责声明:我是一个SQL新手,这是一个类,但我真的可以使用正确的方向戳.
我有这三张桌子:
student(_sid_, sname, sex, age, year, gpa)
section(_dname_, _cno_, _sectno_, pname)
enroll(_sid_, grade, _dname_, _cno_, _sectno_)
(由下划线表示的主键)
我正在尝试编写一个与Oracle兼容的SQL查询,该查询返回一个表,其中包含学生姓名(student.sname
),每个部分中包含最高gpa(包括section.cno
和section.sectno
),以及来自的所有其他属性section
.
我设法使用聚合查询并GROUP BY
获得每个部分的最大GPA:
SELECT MAX(s.gpa), e.cno, e.sectno
FROM enroll e,
student s
WHERE s.sid = e.sid
GROUP BY e.cno, e.sectno
Run Code Online (Sandbox Code Playgroud)
更别说其他section
属性,我甚至无法弄清楚如何处理学生姓名(student.sname
).如果我将它添加到SELECT
子句中,则必须将其包含在GROUP BY
其中弄乱查询的其余部分.如果我在外部查询的WHERE
or FROM
子句中使用这个整个查询,我只能访问表中的三个字段,这没有多大用处.
我知道你不能给我确切的答案,但任何提示都将不胜感激!