小编Ian*_*Ian的帖子

在SLURM中运行程序时如何保存打印语句?

我正在运行一个包含通过SLURM打印语句的Python代码.通常当我通过"python program.py"直接运行Python代码时,print语句出现在终端中.当我通过SLURM运行我的程序时,正如预期的那样,打印语句不会出现在终端中.如何将打印语句保存到文件中,以便在程序运行时检查它们?以下是我通过"sbatch submit.sh"提交的提交脚本.请注意,我已经尝试了两种方法将输出写入test1.out或test2.out.请让我知道我哪里出错了!

#!/bin/bash

#SBATCH -J mysubmission
#SBATCH -p New
#SBATCH -n 1
#SBATCH -t 23:59:00
#SBATCH -o test1.out

module load gnu python

python program.py > test2.out
Run Code Online (Sandbox Code Playgroud)

python slurm

6
推荐指数
3
解决办法
3618
查看次数

如何混合使用字符串文字和浮点数并将它们连接成C中的一个字符串?

我对C有点生疏,我想连接几个字符串和浮点数.特别是,我想创建字符串"AbC",其中A和C是字符串文字,b是浮点数.我知道我必须把浮动变成一个字符串,但我的代码没有编译.下面是我的代码,后面是gcc的输出.有关如何修复我的代码的任何建议?

我的计划:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
double b = 0.5;
char mystring[16];
strcpy(mystring,"A");
strcat(mystring,ftoa(b));
strcat(mystring,"C");
printf("%s",mystring);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

GCC输出:

test2.c: In function ‘main’:
test2.c:11:1: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [enabled by default]
 strcat(mystring,ftoa(b));
 ^
In file included from test2.c:3:0:
/usr/include/string.h:137:14: note: expected ‘const char * __restrict__’ but argument is of type ‘int’
 extern char *strcat (char *__restrict __dest, const char *__restrict __src)
              ^
/tmp/cc77EVEN.o: In function …
Run Code Online (Sandbox Code Playgroud)

c strcat

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

标签 统计

c ×1

python ×1

slurm ×1

strcat ×1