【问题标题】:how to store the variable values in c program?如何在c程序中存储变量值?
【发布时间】:2014-04-28 09:07:46
【问题描述】:

内核变量:

s32 remainder;
s64 quotient ;

如何在 C 程序中读取上述变量值并将它们存储在下面的变量中?

uint32 InterruptLatency;

我正在从内核读取时间,它的类型为 s32 和 s64 为 1.3456;

如何在用户端程序上阅读这个??

uint32 InterruptLatency;
uint8 measurements[32];
char buf[256];
int kernelinterrupt time()
{
    fscanf(fp, "%lu", &InterruptLatency);  // I am reading the data from kernel which is not shown here
    measurements[17] = InterrupLatency;

    // after storing it in buffer I am sending the data from but to another layer
}

是否可以读取变量值(s64 和 s32)并将其存储在 uint32 中断延迟中??

【问题讨论】:

  • incompatible type C error? 的可能重复项
  • @unwind:这不是重复的,虽然它看起来非常相似,但问题是不同的!

标签: c arrays pointers interrupt scanf


【解决方案1】:

使用strcpy 复制字符串。运算符= 不适用于字符串。

【讨论】:

    【解决方案2】:

    不完全确定你想在这里做什么,但使用联合可能会让你到达某个地方。

    typedef union
    {
        uint8 measurements[32];
        char buf[256];
    } measBuf;
    
    measBuf myMeasBuf;
    myMeasBuf.measurements[17] = InterrupLatency;
    //send myMeasBuf.buf to somewhere
    

    需要明确 - 使用联合可能不是您想要的,并且您会非常不稳定,因为这里存在一些系统依赖性。此外,尺寸与我编写的方式不匹配。一般来说,工会可能会在这里为您提供帮助,但您必须看看您是否可以使这项工作适用于您的用例。

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 2021-05-23
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      相关资源
      最近更新 更多