我是Python的新手,这是我第一个替换word的脚本.
我的文件test.c包含以下两行
printf("\nReboot not supported. Exiting instead.\n");
fprintf(stderr, "FATAL: operation not supported!\n");
Run Code Online (Sandbox Code Playgroud)
现在我要替换printf并fprintf通过//printf和//fprintf分别.
这是我尝试过的
infile = open('path\to\input\test.c')
outfile = open('path\to\output\test.c', 'w')
replacements = {'printf':'//printf', 'fprintf':'//fprintf'}
for line in infile:
for src, target in replacements.iteritems():
line = line.replace(src, target)
outfile.write(line)
infile.close()
outfile.close()
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个
fprintf到//f//printf这是错误的.
对于解决方案已经看了这个答案,但不能适应我的脚本.
任何人都知道如何解决它?
我想要printf类型为ipv6地址的值 struct in6_addr 和类型为u_int32_tconsole的ipv4地址.
我尝试过类型转换,但会产生错误
error: aggregate value used where an integer was expected
printf("---------------- ipv4= %zu ipv6 = %zu ",(size_t)ipv4, (size_t)ipv6);
Run Code Online (Sandbox Code Playgroud)
%s ,%lu在堆栈溢出和其他地方经历旧问题之后,我还尝试了许多其他方法.
如果有人有解决方案,我将非常感激.
目前我正在使用Visual Studio 2010(使用C++)编译DLMS库(http://www.gurux.fi/index.php?q=DLMSCOSEMFAQ).
我在调试和发布模式下成功编译了库.但是当我检查两个库的大小然后释放一个库(.lib)有多个双倍大小(76 MB)然后调试一个(31 MB).
我认为第一版的调试版本规模较小,是不是?
VS2010需要进行任何设置吗?
在http://pastie.org/9687316查找构建版本日志
有关调试日志,请访问http://pastie.org/9687340
我写了如下简单的脚本
#!/bin/bash
auth_type=""
SM_Read-only="Yes"
SM_write-only="No"
echo -e ${SM_Read-only}
echo -e ${SM_Write-only}
if [ "${SM_Read-only}" == "Yes" ] && [ "${SM_Write-only}" == "Yes" ]
then
auth_type="Read Write"
else
auth_type="Read"
fi
echo -e $auth_type
Run Code Online (Sandbox Code Playgroud)
当我执行它时,我得到了错误的输出.
./script.bash: line 5: SM_Read-only=Yes: command not found
./script.bash: line 6: SM_write-only=No: command not found
only
only
Read
Run Code Online (Sandbox Code Playgroud)
任何人都知道用" - "(破折号)声明变量的正确方法吗?
编辑:
从c代码获得响应并评估变量,例如
RESP=`getValue SM_ Read-only ,Write-only 2>${ERR_DEV}`
RC=$?
eval "$RESP"
Run Code Online (Sandbox Code Playgroud)
从上面的脚本代码我的c二进制文件getValue知道脚本想要Read-only和Write-only并返回值到脚本eval $RESP.因为在原因错误和我的脚本中我访问变量
echo -e ${SM_Read-only}
echo -e ${SM_Write-only}
Run Code Online (Sandbox Code Playgroud)
这也会导致错误.
我觉得在一个字符串中用C替换两个字符会让人感到困惑.当我将它设置为数组时,它会很好用:
char strBase[8] = "acbdefg";
在这种情况下,我可以交换任何角色.但是当我将其设置为字符串时,它会触发总线错误:
char *strBase = "acbdefg";
非常感谢任何人都可以解释它或给我一些暗示!
#include <stdio.h>
void main ()
{
int i=0;
for (i=0; i<21; i++)
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
printf("%d ",i);
}
getchar();
}
Run Code Online (Sandbox Code Playgroud)
现在这个程序的输出是16 21我不明白为什么这个程序在循环限制小于18时给出这个输出它只给出16但是当值大于18时输出是16 21任何帮助
我有这样的问题:
char *ptr;
float f1 = 12.34;
Run Code Online (Sandbox Code Playgroud)
现在使用这个char*ptr,我想将这个float值转换为string,可以使用这个指针"ptr"在printf中显示.
表示:12.34 ==>"12.34"
我不需要使用任何其他指针或临时变量.我不能用snprintf.