我在编译一个简单的C程序时遇到错误.
#include<stdio.h>
void main()
{
int i=5;
printf("I value is %d",i);
}
Run Code Online (Sandbox Code Playgroud)
错误是......
/usr/local/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我的gcc版本是..
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
谁能知道我的问题是什么?
您将如何有效地(针对运行时进行优化,但同时将空间保持在最低限度)解析和评估 Java 中的一位数算术表达式。
以下算术表达式都是有效的:
eval("-5")=-5
eval("+4")=4
eval("4")=4
eval("-7+2-3")=-8
eval("5+7")=12
Run Code Online (Sandbox Code Playgroud)
我的方法是迭代所有元素,使用标志跟踪当前的算术运算,并逐位评估。
public int eval(String s){
int result = 0;
boolean add = true;
for(int i = 0; i < s.length(); i++){
char current = s.charAt(i);
if(current == '+'){
add = true;
} else if(current == '-'){
add = false;
} else {
if(add){
result += Character.getNumericValue(current);
} else {
result -= Character.getNumericValue(current);
}
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是唯一的最佳解决方案吗?我曾尝试使用堆栈来跟踪算术运算符,但我不确定这是否更有效。我也没有尝试过正则表达式。我之所以这么问,是因为我在一次采访中给出了上述解决方案,并被告知这是次优的。
我有一个名为Det.xml的xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns4:grtHgetRed xmlns:ns2="http://object" xmlns:ns3="http://object" xmlns:ns4="http://object">
<RequestId>lol</RequestId>
<MessageDateTime>54.009</MessageDateTime>
<SenderId>UH</SenderId>
<ReceiverId>GER</ReceiverId>
<TrackingNumber>45</TrackingNumber>
<ServerName>trewds</ServerName>
<ResponseType>success</ResponseType>
<StatusInfo>
<Status>success</Status>
<SystemMessage>Hagert</SystemMessage>
<UserMessage>Hgert</UserMessage>
<Origination>htref</Origination>
</StatusInfo>
</ns4:grtHgetRed>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
我试图从Unix shell脚本中获取它的ResponseType节点值,所以我尝试了以下内容:successxmllint
echo "cat //*[local-name()='S:Envelope'/*[local-name()='S:Body']/*[local-name()='ns4:grtHgetRed']/*[local-name()='ResponseType']" | xmllint --shell Det
.xml | sed '/^\/ >/d' | sed 's/<[^>]*.//g'
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我也没有xpath在我的unix环境中.任何人都可以告诉我这里我做错了什么吗?
所以我使用以下命令获取文件列表,其目录用引号括起来
find /path -type f -mtime -100 -daystart -printf "%f\n" | sed 's/^/"/g' | sed 's/$/"/g' | tr '\n' ' '`
Run Code Online (Sandbox Code Playgroud)
但是现在我只想要那里的文件名所以我添加了
-printf "%f\n"
Run Code Online (Sandbox Code Playgroud)
给我
find /path -type f -mtime -100 -daystart -printf "%f\n" | sed 's/^/"/g' | sed 's/$/"/g' | tr '\n' ' '`
Run Code Online (Sandbox Code Playgroud)
但现在结果不再被引号括起来了.我认为printf命令不会为每个结果创建换行符.
任何帮助,将不胜感激.
我的每一行都有一个十进制数file.txt:
1
2
3
Run Code Online (Sandbox Code Playgroud)
我正在尝试(现在已经太久了)编写一个单行脚本来生成一个输出,其中每一行都有一个带十进制,十六进制和二进制的列.为了简化任务,我们可以说原始数字以字节表示.所以最大值是255.
我首先尝试将每个数字解码为前缀为0的旁数,以便具有8位模式:
awk '{print "ibase=10;obase=2;" $1}' $1 | bc | xargs printf "%08d\n"
其中awk语句中的外部$ 1是file.txt.输出是:
00000001
00000010
00000011
Run Code Online (Sandbox Code Playgroud)十六进制相同,一个前置0
awk '{printf("0x%02x\n", $1)}' $1
和之前一样.输出是:
0x01
0x02
0x03
Run Code Online (Sandbox Code Playgroud)好吧,小数应该只是一个打印:
1
2
3
Run Code Online (Sandbox Code Playgroud)我想要的是我所拥有的一个班轮:
1 00000001 0x01
2 00000001 0x02
Run Code Online (Sandbox Code Playgroud)
所以基本上把1. 2.和3.放在输出的每一行.
我尝试使用system()在awk中执行bc(和其他命令)但没有成功.还有其他方式.你会这样做的方式是什么?
如何忽略所有带名称的文件夹build,bin.我试过这样做
**/bin/
**/build/
Run Code Online (Sandbox Code Playgroud)
但它不起作用.在我看到的git状态
# new file: BS/server/build/obj/sender.o
# new file: BS/server/build/obj/sendistate.o
# new file: BS/server/build/obj/serializedata.o
# new file: BS/client/bin/gc.sample.xml
# new file: BS/client/bin/mkab.qss
# new file: BS/client/bin/mkaberr.qss
# new file: BS/client/build/debug/application.qss
# new file: BS/client/build/debug/config.xml
Run Code Online (Sandbox Code Playgroud) 我正在尝试在字符串中找到子字符串的位置.
#include <string.h>
#include <stdio.h>
void find_str(char const* str, char const* substr)
{
char* pos = strstr(str, substr);
if(pos) {
printf("found the string '%s' in '%s' at position: %d\n", substr, str, pos - str);
} else {
printf("the string '%s' was not found in '%s'\n", substr, str);
}
}
int main(int argc, char* argv[])
{
char* str = "gdeasegrfdtyguh?johh?hugfydsasdrfgthyjkjhghh";
find_str(str, "hh");
find_str("dhenhheme kekekeke hhtttttttttttttttttttttttttttttttttttttttthhtttttttttttt", "hh");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
在'gdeasegrfdtyguhıjohhıhugfydsasdrfgthyjkjhghh'中找到了字符串'hh',位置:19
在'dhenhheme kekekeke hhttttttttttttttttttttttttttttttttttttttttttttttttthtttttttttttttt'中找到字符串'hh',位置:4
在第一个例子中,它表示它处于第19位.但是它不应该说是18吗?因为在第二个例子中它表示4.它从子串的开头开始.
我糊涂了.
我是Java的新手,我必须将C/C++代码转换为Java,我遇到了障碍.由于变量传递给方法的方式,它们在方法中的修改并不简单,我不知道什么是最合理的方法.对于伪代码示例感到抱歉,我希望他们能够清楚地解释我在谈论的内容,而不必深入研究不必要的细节.
我需要一些与C相当的东西
ModifyMyString(type1 &t1,type2 &t2);
Run Code Online (Sandbox Code Playgroud)
(返回类型没关系,它可以是无效的)因为我需要函数来修改t1和t2.
我可以通过在Java中声明来轻松修改其中一个变量,比如说t1
type1 modifyMyString(type1 t1, type2 t2);
Run Code Online (Sandbox Code Playgroud)
并将返回的值分配给
t1 = modifyMyString(t1,t2);
Run Code Online (Sandbox Code Playgroud)
但它只是成功的一半,因为t2的新值丢失了.
我可以宣布新课程
class JustToPassTwoVariables {
type1 t1;
type2 t2;
JustToPassTwoVariables(type1 tt1, type2 tt2) { t1 = tt1; t2 = tt2; }
}
Run Code Online (Sandbox Code Playgroud)
并做一些类似的事情
JustToPassTwoVariables jtptv = modifyMyString(JustToPassTwoVariables(t1,t2));
Run Code Online (Sandbox Code Playgroud)
但我觉得它很笨拙,使代码难以理解.
在绝望中我也可以放弃使用modifyMyString方法的想法,并在每个我称之为modifyMyString的地方重复本地代码 - 但它比使用JustToPassTwoVariables类更没意义.
是否有正确的(或至少广泛使用的,被接受的标准,无论如何)策略来编写Java中的这些东西?
#include <stdio.h>
int myfunc(char *str)
{
char *ptr =str;
while(*ptr++);
printf("%s %s\n",str,ptr);
return ptr-str-1;
}
int main()
{
printf("%d\n", myfunc("Princess Leia"));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
Princess Leia %d
13
Run Code Online (Sandbox Code Playgroud)
ptr如何%d成为字符串?又为何ptr-str-1是13?
我想知道这两个命令有什么区别..
find . –name *.txt
find . –name "*.txt"
Run Code Online (Sandbox Code Playgroud)
我在系统中运行它并且找不到任何区别,标志有" "什么作用?