我有这个脚本
#!/bin/sh
if [ $# -ne 3 ] ; then
echo "param 1, param2, and A or B "
exit 1;
elif [ $# -eq 3 ]; then
if [$3 = "A"] ; then
echo "A"
elif [$3 = "B"]; then
echo "B"
fi
fi
Run Code Online (Sandbox Code Playgroud)
它基本上检查参数3是A还是B,然后做回声.但它返回:
./test.sh: line 6: [A: command not found
./test.sh: line 8: [A: command not found
Run Code Online (Sandbox Code Playgroud)
我试图-eq用于比较,但它仍然无效.我该如何解决这个问题?
是否有任何类似于"_file_"或"_line_"在go中的函数,以了解谁在运行时调用特定函数?在C中,我们有"_file_"可以称为宏的行.怎么做去?
我的数据库中有一个表是房子,有很多字段,如"颜色","价格".如何在更新后仅保存特定字段
如果我有这个,
@ house.colour = newcolour
@ house.save
它将保存所有其他字段,包括house.colour和house.price
(我的情况下,价格应该以编程方式同时更新颜色,但不应保存.只有house.colour应保存在数据库中)
我试着做
@ house.colour = newcolour
@ house.colour.save
但它显示我的错误
是否只能保存@ house.colour的值?
谢谢你的任何建议
我刚刚了解了C,我知道这是一个基本问题,但我无法弄清楚如何解决这个问题.例如,我有一行
printf("value :%d\n",var.value);
Run Code Online (Sandbox Code Playgroud)
格式不适合,因为它显示下面的错误
*格式'%d'需要类型'int',但参数3的类型为'uint32_t*'
我已经检查了cplusplus的参考:cplusplus print ref
但它没有明确说明如何打印类型为uint32_t*(同样uint16_t)的值.
任何解释都将非常感激.
我尝试创建一个简单的函数,将切片值附加到创建的 csv 文件的下一列。目的是在 test.csv 中使用这种样式
|A 列 |B 列|
|标题1 |标题2|
|第一价值| 第二价值 |
(很抱歉格式错误,但是一旦生成了 text.csv,如果我们打开 text.csv 文件,想法是将“SECONDVALUE”放在“FIRSTVALUE”之后的下一列中(如中所示)上图)..并且每次调用该函数时,它都会在同一行的上一列之后继续附加下一个值)。
这就是我得到的程度,但是它直接将 SECONDVALUE 附加到 FIRSTVALUE 的同一列上。(所以我得到的不是 "|FIRSTVALUE | SECONDVALUE" ,而是 "|FIRSTVALUESECONDVALUE|" )
package main
import (
"encoding/csv"
"fmt"
"os"
"strings"
)
func main() {
callfunc()
}
func callfunc() int {
testval1 := []string{"FIRST VALUE"}
test(testval1, "test.csv", 1)
testval2 := []string{"SECOND VALUE"}
test(testval2, "test.csv", 0) //I want this to be added to the column next to first value
return 1
}
func test(lines []string, …Run Code Online (Sandbox Code Playgroud) 我对此代码有疑问.我在我的框架中编写了这段代码,导致框架崩溃.但是当我在一个文件中重写下面的代码时,它的工作正常.我只是想知道,下面的代码是否正确的内存分配和释放它?(特别是对于msg-> context_var.type = f;的部分)谢谢
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int value;
int price;
int old;
} type_t;
typedef struct {
type_t *type;
} context_t;
typedef struct {
context_t context_var;
} send_request;
void send_Message(send_request *msg)
{
type_t *f = 0;
f = malloc(sizeof(f));
msg->context_var.type = f;
msg->context_var.type->price = 1;
msg->context_var.type->value = 100;
msg->context_var.type->old =120;
printf("value of %d/n", msg->context_var.type->price);
free(f);
}
int main()
{
send_request *msg = 0;
msg = (send_request *) malloc(sizeof(send_request));
send_Message(msg);
free(msg);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我是C的新手,试图调用一个函数,但它给了我错误,我无法理解为什么
int set_price(&colour-> type.name);
它回报了我 expected ‘uint32_t’ but argument is of type ‘uint32_t *’. warning: passing argument ‘int set_price’ makes integer from pointer without a cast
指针在哪里
house_list*color = NULL;
和name在struct中定义
uint32_t名称;
原来的功能接受
int set_price(uint32_t name)
{
/ 在这里做点什么/
}
我做错了什么?如果在struct成员中,name被定义为uint32_t,并且我定义了一个指针颜色,我相信我需要在colour-> type之前使用&并且在name之前使用dot不是吗?
谢谢