我正在尝试adduser从perl 启动命令.
use strict;
use warnings;
my @test=('/usr/sbin/useradd',
"-c 'Fred'",
'-d /vol2/home/DMZ/f.kals',
'-g 3335','-u 11002',
"-k '/dev/null'",
'-m',
'-p "$1$kKNKMa8O$g03oj6YeeZbO2i3NMSoyT1"',
'fred');
system (@test);
Run Code Online (Sandbox Code Playgroud)
当我执行上面的操作时,我得到以下输出:
[ay@pandora /vol2]$ sudo ./test.pl
useradd: invalid home directory ' /vol2/home/DMZ/fred'
Run Code Online (Sandbox Code Playgroud)
为什么?
如果我不使用数组
my $command="/foor/bar/useradd -m -g 1234 -u 6789 -param2 -param3 username"
system ($command);
Run Code Online (Sandbox Code Playgroud)
那工作正常..为什么不是阵列?
如何使用指针算法打印结构的特定成员?我有一个有2名成员的结构.我想j通过操纵指向该结构的指针的内存来打印出成员.
#include <stdio.h>
#include <conio.h>
typedef struct ASD
{
int i;
int j;
}asd;
void main (void)
{
asd test;
asd * ptr;
test.i = 100;
test.j = 200;
ptr = &test;
printf("%d",*(ptr +1));
_getch();
}
Run Code Online (Sandbox Code Playgroud) 首先,为长期解释道歉.
class A(object):
def __init__(self, klass):
print "A::__init__()"
self._klass = klass
def __call__(self):
print "A::__call__()"
return self._klass()
def __del__(self):
print "A::__del__()"
@A
class B(object):
def __init__(self):
print "B::__init__()"
def main():
b = B()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
A::__init__()
A::__call__()
B::__init__()
A::__del__()
Run Code Online (Sandbox Code Playgroud)
class A(object):
def __init__(self, klass):
print "A::__init__()"
self._klass = klass
def __call__(self):
print "A::__call__()"
return self._klass()
def __del__(self):
print "A::__del__()"
class Parent1(object):
def __init__(self):
print "Parent1:: __init__()"
super(Parent1, self).__init__() …Run Code Online (Sandbox Code Playgroud) 我正在编译这个程序,编译顺利.我执行它的那一刻,它失败了,free(): invalid pointer错误.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p = NULL;
if ((p = (char *) malloc((int)sizeof(char) * 100)) == NULL) {
printf("ERROR: unable to allocate memory\n");
return -1;
}
p += 50;
free(p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用gcc -o memtest m.c命令编译.
是否有任何GCC编译器选项会在编译期间给出关于这些无效指针错误的警告/错误/指示?
我知道,这可能是常识,但有编辑从Windows窗口的像素的RGB值的方法C/ C++不使用库,例如OpenGL或DirectX?如果有,有什么内置函数可以直接操作像素缓冲区?
我读到__packed__从这里和,我理解,当__packed__在使用struct或union,这意味着该成员变量被放置在这样的方式以最小化来存储所需的存储器struct或union.
现在,考虑以下代码中的结构.它们包含相同的元素(相同type,相同的变量名称,并以相同的顺序放置).区别在于,一个是__packed__,另一个不是.
#include <stdio.h>
int main(void)
{
typedef struct unpacked_struct {
char c;
int i;
float f;
double d;
}ups;
typedef struct __attribute__ ((__packed__)) packed_struct {
char c;
int i;
float f;
double d;
}ps;
printf("sizeof(my_unpacked_struct) : %d \n", sizeof(ups));
printf("sizeof(my_packed_struct) : %d \n", sizeof(ps));
ups ups1 = init_ups();
ps ps1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法我们可以将解压缩的结构复制ups1到打包结构ps1而不做一个member-variable-wise-copy?这样的东西memcpy() …
在c中,假设你有以下结构和一个实例:
#include <stdio.h>
#include <stdlib.h>
int main()
{
typedef struct _a {
int *a1;
float *a2;
char *a3;
}a;
a b;
b.a1 = (int *) malloc(sizeof(int) * 10);
b.a2 = (float *) malloc(sizeof(float) * 10);
b.a3 = (char *) malloc(sizeof(char) * 10);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,如何找到分配/与变量b关联的总内存?sizeof(b)将返回结构中指针的组合大小,但不会计算使用malloc为不同类型/大小分配的内存总和.如何在内存中找到此结构的总大小(包括填充,如果适用)?
我正在尝试做这样的事情
#define GETCART1 0;
#define GETCART2 1;
void helper(int *Array,int length,int counter, int option){
if (length > counter){
switch(option){
case (GETCART1) :
break;
}//switch
}
}
Run Code Online (Sandbox Code Playgroud)
我得到编译错误,当我更换GETCART1使用0其作品的罚款.这是为什么?