小编Ger*_*rdh的帖子

Link keyrings in initramfs using syscall()

I want to load certificates for IMA/EVM into Linux keyrings.

The related shell commands are

ima_id=`keyctl newring _ima @u`
evm_id=`keyctl newring _evm @u`
evmctl import  /etc/keys/x509_ima.der $ima_id
evmctl import  /etc/keys/x509_evm.der $evm_id
Run Code Online (Sandbox Code Playgroud)

This nearly works except for a problem with permissions.

# keyctl show @u
Keyring
 272896171 --alswrv      0 65534  keyring: _uid.0
 406281657 --alswrv      0     0   \_ keyring: _ima
keyctl_read: Permission denied
Run Code Online (Sandbox Code Playgroud)

Searching the web I found this: https://github.com/systemd/systemd/issues/5522

And the workaround is to link the keyrings:

keyctl link @us @s …
Run Code Online (Sandbox Code Playgroud)

c linux security system-calls

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

jsoncpp查找成员函数

我在Win32平台上使用jsoncpp 库的v1.6.2。一切都很好,我能够解析 json 并使用etc成功访问。Json:Valuesv.["firstname"]

Json:Value问:如何在 json 结构中按名称查找?在我发现的文档中:

Value const * Json::Value::find ( char const *key,char const *end ) const
Run Code Online (Sandbox Code Playgroud)

但它没有具体说明'end'是什么。我已经尝试过"",但它没有返回任何我可以使用的东西。

我是否应该尝试以这种方式找到东西?

我发现文档非常稀疏,因此一些 jsoncpp 程序示例会非常有帮助。

谢谢

c++ json jsoncpp

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

从函数返回 FILE 指针并在 main 上处理它

我试图将FILE某个函数的指针返回到main(). 之后,我尝试fprintf在指针上做一些事情,但没有奏效。这是我的代码:

我的功能:

FILE *create_file(void){

    FILE *regularTxt = NULL;
    regularTxt = fopen("MyLogExamplekkggggggk.txt", "wt");
    if (!regularTxt){
        printf("error with regtxt");
        getchar();
        return 1;
    }
    char first_part_string[] = "kkkkik";
    fprintf(regularTxt, "%s\n\n\n%s", "ttttg", "lklf");
    return regularTxt;
}
Run Code Online (Sandbox Code Playgroud)

main函数:

int main(void)
{
    p_txt = create_file();
    fprintf(p_txt, "%s\n\n\n%s", "gggg", "lklf");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

错误 92 错误 C4703:使用了可能未初始化的局部指针变量“p_txt”

c pointers file

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

反转用户输入的整数字符串(C)

我想做的是反转用户输入的数字字符串。发生的事情是它会编译并运行,直到我在输入文件后按Enter scanf。然后我得到一些Microsoft运行时错误...出了什么问题???

注意:这是家庭作业,但是我已经弄清楚了逻辑。让我感到困惑的是这个错误。

#include <stdio.h>
int main()
{
    unsigned int giveStr = 0;
    char* charIt;
    printf("Enter a number to be reversed.\t");
    scanf("%d", &giveStr);
    fflush(stdin);
    sprintf(charIt, "%d", giveStr);
    revStr(giveStr);
    getchar();
    return 0;
}

revStr(unsigned int n)
{
      char buffer[100];
      int uselessvar, counter = 0;
      for (; n > 0;)
      {
           uselessvar = sprintf(&buffer[counter], "%d", n);
           counter++;
      }
      for (counter = 0; counter > 0;)
      {
          printf("%c", buffer[counter]);
          counter--;
      }
      return 0;
}
Run Code Online (Sandbox Code Playgroud)

编辑:刷新换行符的stdin:/并在此仅使用该程序进行映像。与我的。

c string reverse

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

如何计算可以组成的三角形数量

下面的代码应该计算出给定范围 1...N 中 3 个不同整数的每个三元组可以形成的三角形的数量。然而,当我输入 5 时,它给出的是 34,而正确答案是 3:唯一可能的三角形是 (2, 3, 4)、(2, 4, 5) 和 (3, 4, 5)。

 // C code to count the number of possible triangles using

  #include <stdio.h>
  int main()
  {   int N, count=0;
      setvbuf(stdout, NULL, _IONBF, 0);
      printf("Please input the value of N: \n");
      scanf("%d", &N );
      for (int i = 1; i < N; i++) {
          for (int j = 1; j < N; j++) {
              // The innermost loop checks for the triangle
              // …
Run Code Online (Sandbox Code Playgroud)

c

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

微控制器和外部闪存之间的连接

我在我的项目中使用stm32f2xx系列控制器.我想知道在没有对外部闪存进行任何读/写操作的情况下是否将外部闪存连接到微控制器.那可能吗?

如果是,请解释这样做的方法.

如果重要,控制器和外部闪存之间的通信是SPI.

提前致谢.

microcontroller flash-memory

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

'new' 未声明(首次在此函数中使用)

此代码用于哈密顿循环我无法解决此错误:

    In function ‘hamCycle’:
   error: ‘new’ undeclared (first use in this function)
         int *path = new int [V];
                     ^
 note: each undeclared identifier is reported only once for each function it appears in
 error: expected ‘,’ or ‘;’ before ‘int’
         int *path = new int [V];
                         ^
Run Code Online (Sandbox Code Playgroud)

哈密​​顿循环代码是:

/*
 * C Program to Find Hamiltonian Cycle
 */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define V 5

void printSolution(int path[]);

/* 
 * check if the vertex v can be added at …
Run Code Online (Sandbox Code Playgroud)

c

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

是否可以更改 C++ 中向量的开始位置以清除其前 n 个元素?

假设我有一个整数向量 [1,2,3,4,5,6,7]。据我所知,向量有一个内存地址@v,然后如果我们想访问一个元素i,我们只需要执行@v+i*size_of_element。也许我错了, std::vector 是以不同的方式实现的。

如果我想删除前 4 个元素并最终得到 [5,6,7],我是否只需要更新 @v 并清除元素,在这种情况下它们只是整数,所以我假设它将是 O(1)。

我的假设是否错误,有什么方法可以使用向量在 C++ 中实现此目的,即更新向量的起始地址以“清除”前 n 个元素?

如果没有,是否可以使用 std::list ?

c++ list vector

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

它只运行第一个“如果”为什么会这样?

即使我输入了另一个日期,它也只会打印“星期日”。我该如何解决这个问题?我通常不使用 int main() 但是我的一个朋友使用了这个方法并且它有效但是我使用的是学校编写的程序所以我不能直接粘贴它。但我很确定我正确地复制了它

#include <stdio.h>

int date;

int main()

{

    printf(" \n\n              JUNE 2020           \n");
    printf(" SUN   MON   TUE   WED   THU   FRI   SAT \n");
    printf("        1     2     3     4     5     6  \n");
    printf("  7     8     9    10    11     12    13 \n"); 
    printf(" 14    15    16    17    18     19    20 \n");
    printf(" 21    22    23    24    25     26    27 \n");
    printf(" 28    29    30 \n\n\n");

    printf("Here is your schedule for June 2020         \n");
    printf("Please select a date: ");

    scanf("%d", &date); …
Run Code Online (Sandbox Code Playgroud)

c

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

结构的 malloc 上的分段错误(核心转储)

我有一个由线路引起的分段错误错误

*head = malloc(sizeof(struct node)+1);'
Run Code Online (Sandbox Code Playgroud)

我很确定我在其他情况下以相同的方式使用了构造节点和 malloc,一切都工作正常。程序在此处打印1,然后发生核心转储。

这是我的代码:

struct node {
    //int val ;
    struct node * next;
    unsigned char string[];
 } ;

void init_list(struct node ** head) {
    
    printf("here1 \n");
    fflush(stdout);
    *head = malloc(sizeof(struct node)+1);
    printf("here2\n"); 
    fflush(stdout); 
    if(!(*head)){
    
            printf("error malloc \n");
            fflush(stdout);
            return ;
    }
    //(*head) -> val = -1; 
    (*head) -> next = NULL;
    ((*head) -> string)[0]= '\0'; 
    return ;

  }

  int main(void) {
     struct node ** head;
     init_list(head) ;
     printf("hereee\n");
     fflush(stdout) ;
     fini_list(head);
     return 1;
  }
Run Code Online (Sandbox Code Playgroud)

这是 …

c

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

Scanf complie错误;我需要了解编译此程序时发生的错误

#include<stdio.h>
#define N 16
int main(void)
{
 int borrow=0;
 int radix=2;
 int i=0;
 int x[N]={0};
 int y[N]={0};
 int di[N]={0};
 int hex1;
 int hex2;
 int j;

 scanf("%i,%i,&hex1,&hex2");

//error: warning: format ‘%i’ expects a matching ‘int *’ argument [-Wformat=]

 scanf("%i,%i,&hex1,&hex2");//
           ^

//error2:format ‘%i’ expects a matching ‘int *’ argument [-Wformat=]

scanf("%i,%i,&hex1,&hex2");//
              ^
}
Run Code Online (Sandbox Code Playgroud)

c

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

c语言十进制转二进制

我对编码很陌生。这是我编写的一个程序,用于将十进制转换为二进制,但有一个问题我得到的结果是相反的

示例:122is 的二进制,1111010我正在获取 output 0101111

谁能告诉我是否可以在我的代码中反转输出?或者我可以在以下进行哪些更改以获得正确的输出?

#include<stdio.h>
int main()
{
 int n, q, r;
    
    printf("Enter the decimal Number : ");
    scanf("%d", &n);
    int num=n;
    while(n!=0)        
    {
        r=n%2;
        q=n/2;
        printf("%d", r);
        n=q;
    }
    return 0;   
}
Run Code Online (Sandbox Code Playgroud)

c

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