小编for*_*ght的帖子

使用python与bash

import os
ot = os.popen("%s") %"ls"
Run Code Online (Sandbox Code Playgroud)
TypeError: unsupported operand type(s) for %: 'file' and 'str'
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么会发生错误.我的意思是它是纯粹的字符串操作,对吗?任何帮助都可以得到赞赏.

python bash popen

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

为什么在尝试将原始指针值赋予新值时会导致错误?

我是C语言的新手,我正在尝试使用如下指针.

  1. po1被定义为指向地址的指针.PC为其分配1个字节的内存.po2是一样的.我想得到指向的内存地址po2,但只得到一个意外的0,显然不是地址.

    #include <stdio.h>
    int main(int argc, char *argv[]) {
        char *po2, *po1;
        printf("---%d---\n", po2); 
        return 0;
    }
    
    Run Code Online (Sandbox Code Playgroud)

    输出是:

    demo11.c:5:23:警告:格式指定类型'int'但参数的类型>'char*'[-Wformat] printf(" - **** - %d - **** - \n",po2); 生成了~~ ^ ~~%s 1个警告. - **** - 0 - **** -

  2. 然后我试图给foo内存po2指向的值,但它给出了一个错误.

    #include <stdio.h>
    int main(int argc, char *argv[]) {
        char *po2, *po1;
        char foo = 'D';
        *po2 = foo;
        printf("%c---------------\n", *po2); 
        return 0;
    }
    
    Run Code Online (Sandbox Code Playgroud)

    输出是:

    由于信号终止:分段故障(11)

显然,错误是由声明引起的*po2 = …

c pointers

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

标签 统计

bash ×1

c ×1

pointers ×1

popen ×1

python ×1