小编Bil*_*nch的帖子

使用 echo 和 system 在 C 中运行软件

我正在尝试运行一个名为 BLASTP 的生物程序,它接收两个字符串(代码中的 fasta_GWIDD 和 fasta_UNIPROT)并比较它们。我遇到的问题是在代码中使用了 echo/system。谁能建议我错过了什么?

    for(i=0;i<index1;i++)
    {
        sprintf(fasta_GWIDD,">%s\\n%s\n",fasta_name1[i],fasta_seq1[i]);
        setenv("GwiddVar", fasta_GWIDD, 1) ;
        sprintf(fasta_UNIPROT,">%s\\n%s\n",fasta_name2[i],fasta_seq2[i]);
        setenv("UniprotVar", fasta_UNIPROT, 1) ;
        system("blastp -query <(echo -e $GwiddVar) -subject<(echo -e $UniprotVar)");
    }
Run Code Online (Sandbox Code Playgroud)

错误是:

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `blastp -query <(echo -e $GwiddVar) -subject<(echo -e $UniprotVar)'
Run Code Online (Sandbox Code Playgroud)

c shell blast

1
推荐指数
1
解决办法
524
查看次数

带数组的postincrement指针

无法理解为什么a [1]的值不等于10

void main()
{
    int a[]={2,1};
    int *ptr=a;
    *ptr++=10; //trying to update a[1]=10
    printf("%d",*ptr);
} 
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下吗?

c pointers

1
推荐指数
1
解决办法
219
查看次数

有人可以向我解释这个python行为吗?

有人可以解释这种行为吗?当我运行代码时,它会打印10,然后是20.为什么list_of_classes要更改,即使我只更改了bob的值?我不应该用新值更新列表吗?

class wooo():
    def __init__(self,x,y,name):
        self.x=x
        self.y=y
        self.name=name

bob=wooo(10,10,"bob")
joe=wooo(10,10,"joe")
list_of_classes=[bob,joe]
print(list_of_classes[0].x)
bob.x=20
print(list_of_classes[0].x)
Run Code Online (Sandbox Code Playgroud)

实际产出

10
20
Run Code Online (Sandbox Code Playgroud)

预期产出

10
10
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
59
查看次数

固定的(和包括)100和149之间的随机数范围

键入两个语句,用于rand()在(和包括)100和149之间打印2个随机整数.以换行符结束.例如:

101
133
Run Code Online (Sandbox Code Playgroud)

我试过了...

cout << rand() % 100 << endl;
cout << rand() % 149 << endl;
Run Code Online (Sandbox Code Playgroud)

......而且无法让它发挥作用.

我非常困惑.任何帮助,将不胜感激!

c++ random

1
推荐指数
1
解决办法
4176
查看次数

警告:格式'%d'需要类型'int',但参数6的类型为'long int'

我在编译过程中收到此警告.

"警告:格式'%d'需要类型'int',但参数6的类型为'long int'

我应该%d改成%lu吗?

编辑:这是代码的一部分.

if (item->GetVnum() == DRAGON_HEART_VNUM)
{
    sprintf(buf, "Inc %ds by item{VN:%d SOC%d:%d}", ret, item->GetVnum(), ITEM_SOCKET_CHARGING_AMOUNT_IDX, item->GetSocket(ITEM_SOCKET_CHARGING_AMOUNT_IDX));
}
else
{
    sprintf(buf, "Inc %ds by item{VN:%d VAL%d:%d}", ret, item->GetVnum(), ITEM_VALUE_CHARGING_AMOUNT_IDX, item->GetValue(ITEM_VALUE_CHARGING_AMOUNT_IDX));
}
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
1566
查看次数

是什么导致c中printf命令的这个奇怪的输出,我该如何阻止它发生?

这段代码产生了下面的奇怪输出.我尝试将字符数组增加到13并打印整个字符串,但最后仍然有奇怪的字符.我在Windows上使用MinGW.这可能是原因吗?

#include <stdio.h>
#include <string.h>
int main() {
    char message[10];
    int count, i;
    strcpy(message, "Hello, world!");
    printf("Repeat how many times? ");
    scanf("%d", &count);
    for(i=0; i < count; i++)
        printf("%3d - %s\n", i, message);
    if(i==count)
        getch();
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

c

1
推荐指数
1
解决办法
74
查看次数

VHDL 中的并发语句非法?

我一直在尝试学习如何在 VHDL 中使用条件信号分配(我相信哪些是 WHEN ELSE 语句?),并提出了应该是一个简单的代码。但 ModelSim 不让它编译并一直告诉我我有一个非法的并发语句。在哪里?为什么?我尝试在进程内执行 IF ELSIF ELSE 语句,但仍然遇到完全相同的错误,所以我现在比开始时更困惑......

Library ieee;
Use ieee.std_logic_1164.all;

Entity Q59122 is port (
    A, B : IN  STD_LOGIC;
    Y    : OUT STD_LOGIC
);
End Entity Q59122;

ARCHITECTURE csa OF Q59122 IS
BEGIN
    Y <= '0' WHEN A = '0'
    ELSE Y <= '0' WHEN B = '0'
    ELSE Y <= '1';
END csa;
Run Code Online (Sandbox Code Playgroud)

基本上我正在尝试使用条件信号分配来模拟与门。我知道您可以在 VHDL 中使用“and”命令,但这会达不到目的。我在这里先向您的帮助表示感谢。

vhdl

1
推荐指数
1
解决办法
2万
查看次数

python float值和c float值有什么区别?

我正在用两种不同的语言来回答同样的问题。得到了不同的结果。需要帮助以了解为什么会这样吗?

我用python编写了相同的代码,得到的结果与C预期的结果不同。

代码1:

{
  float f = 0.1;
  if (f == 0.1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

Run Code Online (Sandbox Code Playgroud)

代码2:

f = float()
f = 0.1
if (f == 0.1):
    print("YES")
else:
    print("NO")
Run Code Online (Sandbox Code Playgroud)

两者必须提供与否相同的输出。但是只有C给出了预期的输出,而Python给出的是YES。

c python

1
推荐指数
1
解决办法
69
查看次数

如何在 C++ 中使用 std::accummulate 计算总和立方体

假设我有一个范围,我想计算每个元素的立方体总和,例如[1,2,3]我想要的:

1 3 + 2 3 + 3 3 = 36

我将如何使用std::accummulate(),我必须编写自己的二进制函数来做到这一点?我有:

std::accummulate(iterator to beginning,
                 iterator to end of range,
                 0.0,
                 [](int i, int j) { return i*i*i + j*j*j; });
Run Code Online (Sandbox Code Playgroud)

但这由于某种原因不起作用。

问题就出来了不可思议,但在我的回报,我只是乘以ij用自己3次加入。

c++ stl std range

1
推荐指数
1
解决办法
65
查看次数

请帮助编译这个程序

#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>

void *WriteNumbers(void *threadArg)
{
 int start, stop;
 start = atoi((char *)threadArg);
 stop = start + 10;

 while(start<stop)
 {
  printf("%d\n", start++);
  sleep(1);
 }
}

int main(int argc, char **argv)
{
 pthread_t thread1, thread2;

 // create the threads and start the printing 
 pthread_create(&thread1, NULL, WriteNumbers, (void *)argv[1] );
 pthread_create(&thread2, NULL, WriteNumbers, (void *)argv[2]);

 pthread_join(thread1, NULL);
 pthread_join(thread2, NULL);

 return 0;
}
Run Code Online (Sandbox Code Playgroud)
gcc -o pthread pthread.c 
/tmp/cckJD3rd.o: In function `main':
pthread.c:(.text+0x7a): undefined reference to `pthread_create'
pthread.c:(.text+0xa2): undefined reference to `pthread_create' …
Run Code Online (Sandbox Code Playgroud)

c linux pthreads

0
推荐指数
2
解决办法
622
查看次数

标签 统计

c ×5

c++ ×3

python ×2

blast ×1

linux ×1

pointers ×1

pthreads ×1

random ×1

range ×1

shell ×1

std ×1

stl ×1

vhdl ×1