我在实现for循环时遇到问题.我执行脚本时遇到此错误
test1.sh:2:语法错误:循环变量错误
我不明白这个错误.
这是我的剧本
#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done
Run Code Online (Sandbox Code Playgroud)
任何人都可以在ubuntu中告诉我for循环的语法(在ubuntu中它链接到破折号shell)shell吗?
我正在尝试在C中的shell中实现多个管道.我在这个网站上找到了一个教程,我所做的功能就是基于这个例子.这是功能
void executePipes(cmdLine* command, char* userInput) {
int numPipes = 2 * countPipes(userInput);
int status;
int i = 0, j = 0;
int pipefds[numPipes];
for(i = 0; i < (numPipes); i += 2)
pipe(pipefds + i);
while(command != NULL) {
if(fork() == 0){
if(j != 0){
dup2(pipefds[j - 2], 0);
}
if(command->next != NULL){
dup2(pipefds[j + 1], 1);
}
for(i = 0; i < (numPipes); i++){
close(pipefds[i]);
}
if( execvp(*command->arguments, command->arguments) < 0 ){
perror(*command->arguments);
exit(EXIT_FAILURE);
}
} …Run Code Online (Sandbox Code Playgroud) 我想在不使用任何框架的情况下在引导模式中验证表单.它实际上是一个简单的模态,只有一个输入文本和两个按钮"关闭"和"发送".用户应在输入框中键入他/她的名字,然后单击"发送".表单是使用方法发送的.
我想要做的是,如果用户没有在输入框中输入任何内容并单击"发送"按钮,则输入框应该有一个红色边框,而不是默认的蓝色边框.这是我的模态的代码:
<div id="myModal" class="modal fade" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<!--form-->
<form class = "form-horizontal" id="myForm" method="post" action="test.php" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">My modal</h4>
</div>
<div class="modal-body">
<p>
Please enter your name:
</p>
<br/>
<div class="form-group">
<div class="col-lg-12">
<label class="control-label" for="firstname">Name</label>
<input type="text" class="form-control required" id="firstname" name="firstname">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="myFormSubmit" class="btn btn-primary">Send</button>
</div>
</form>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试使用javascript更改输入文本的类,has-error但它不会产生红色轮廓.当我点击发送它通过post方法而不是Here这是我的javascript代码发送空值:
<script type="text/javascript">
$('#myForm').validate({
rules: …Run Code Online (Sandbox Code Playgroud) 我有2张桌子.其中一个表有7个值,另一个表有5个值.这些表的主键是共同的.我想以这种方式加入两个表:如果我有一个表
English French
-------------------- --------------------
one Un
two Deux
three Trois
four Quatre
four Quattro
five Cinq
five Cinco
Run Code Online (Sandbox Code Playgroud)
还有一个:
English French
-------------------- --------------------
one aaaaa
two bbbbb
three ccccc
four
five
Run Code Online (Sandbox Code Playgroud)
我想要一个这样的表:
English French
-------------------- --------------------
one Un
one aaaaa
two Deux
two bbbb
three Trois
three ccccc
four Quatre
four Quattro
four --------
five Cinq
five Cinco
five ----------
Run Code Online (Sandbox Code Playgroud)
我尝试使用加入,但它确实值的线性组合four和five.我该怎么做呢?谢谢.
编辑:SQL查询:
SELECT l.date_location, l.duree, r.km_restitution, r.km_parcouru
FROM locations l, restitutions r
UNION
SELECT …Run Code Online (Sandbox Code Playgroud) 我在修改C中的数组时遇到一些问题.我有两个数组,c1和c2.
我想c2通过输入单词array c1contains 手动填充数组.用户键入一个字母,如果在c1中找到此字母,程序会将此字母修复在c2中的适当位置.如果该字母不属于c1,则不执行任何操作.这就像一个"猜词"游戏.这是一个草图:
c1 = MARRON
c2: ******
Type a letter: E
c2: ******
Type a letter: A
c2: *A****
Type a letter: O
c2: *A**O*
Type a letter: P
c2:*A**O*
Type a letter: M
c2: MA**O*
Type a letter: N
c2: MA**ON
Type a letter: R
c2: MARRON
You win.
Run Code Online (Sandbox Code Playgroud)
我的代码并没有真正遵循上面的草图.我的问题是在合适的时间打印星号和字母.我还发现程序用'\0'星号替换了最后一个字符,即使我保留了一个条件来防止这种情况.这是'我的代码:
void complete( char *c2, char c1[], int letter ) {
int i = 0;
for( i = 0; i < strlen( c1 …Run Code Online (Sandbox Code Playgroud) 我想动态地更改写在JTextPane上的某些文本.我有一个String数组,其中包含应该更改的单词
String ListMethod [] = {"forward", "backward", "left", "right"};
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些帖子,许多人建议使用JTextPane或JEditorPane来编辑文本,但大部分答案都是针对静态文本的.我希望以这样的方式进行:当我在文本窗格中键入"向前"或"向后"等时,它会检测到这些单词并更改颜色.我该怎么办呢?
谢谢你的帮助.
我将在linux中编写一个简单的shell,它可以实现包括环境变量在内的各种东西.我尝试使用这些变量打印,getenv但我遇到了一些问题.即使用户输入正确的变量,也getenv总是返回.这是我的代码NULL$HOME
int i = 0;
if(strcmp(cmdArgv[i], "echo") == 0){
char *variable;
for(i = 1; cmdArgv[i] != NULL; i++){
variable = getenv(cmdArgv[i]);
if(!variable){
puts("not a variable");
printf("%s ", cmdArgv[i]);
}else{
puts("a variable");
printf("%s ", variable);
}
}
printf("\n");
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
它没有进入else条件.例如,如果用户键入echo ls $HOME.此输入被解析为cmdArgva char **.然后我的输出是
not a variable
ls
not a variable
$HOME
Run Code Online (Sandbox Code Playgroud)
但是$HOME是一个变量,所以也许我的实现getenv是不对的.关于什么似乎是问题的任何想法?谢谢.
如何才能按字母顺序列出TST包含的单词?
与按顺序遍历可以解决问题的BST不同,TST不起作用。前遍历和后遍历都不会。
更重要的是,与某些BST实现的节点相反,TST的节点包含字母而不是单词。从左节点移动到右节点时,有些字母不包括在内。
我似乎可以绕开它。
下图按字母顺序显示了TST的单词列表。

algorithm tree tree-traversal data-structures ternary-search-tree