小编Lio*_*mov的帖子

初始化字符串数组

什么是正确的初始化方法char**?我在尝试时遇到覆盖错误 - 未初始化指针读取(UNINIT):

char **values = NULL;
Run Code Online (Sandbox Code Playgroud)

要么

char **values = { NULL };
Run Code Online (Sandbox Code Playgroud)

c initialization

28
推荐指数
3
解决办法
10万
查看次数

如何将MAC地址(字符串中)转换为整数数组?

如何将字符串中的MAC地址转换为C中的整数数组?

例如,我有以下字符串存储MAC地址:

00:0D:3F:CD:02:5F

我如何将其转换为:

uint8_t array[6] = {0x00, 0x0d, 0x3f, 0xcd, 0x02, 0x5f}
Run Code Online (Sandbox Code Playgroud)

c arrays string

8
推荐指数
2
解决办法
2万
查看次数

编译时出错C2676

我正在尝试用C++编写代码(使用模板)来添加2个矩阵.

我在.h文件中有以下代码.

#ifndef __MATRIX_H__
#define __MATRIX_H__

//***************************
//         matrix
//***************************

template <class T, int rows, int cols> class matrix {
public:
    T mat[rows][cols];
    matrix();
    matrix(T _mat[rows][cols]);
    matrix operator+(const matrix& b);
};

template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (T _mat[rows][cols]){
    for (int i=0; i<rows; i++){
        for (int j=0; j<cols; j++){
            mat[i][j] = _mat[i][j];
        }
    }
}

template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (){
    for (int i=0; i<rows; i++){
        for (int j=0; …
Run Code Online (Sandbox Code Playgroud)

c++

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

char*malloc的strlen

我有以下代码

char *new_str;
int size_in_bytes;
int length;

size_in_bytes = 2*sizeof(char);
new_str = (char *)malloc(size_in_bytes);
length = strlen(new_str);
Run Code Online (Sandbox Code Playgroud)

期望长度为2,实际上是16.有人可以解释为什么吗?

malloc strlen

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

使用c ++模板进行Martices乘法运算

既然你很有帮助,我还有另外一个问题.

我已经使用模板实现了矩阵乘法,但我无法编译我的代码.

这里是.

matrix.h:

#ifndef __MATRIX_H__
#define __MATRIX_H__

template <class T, int rows, int cols> class matrix {
public:
    T mat[rows][cols];
    matrix();
    matrix(T _mat[rows][cols]);
    matrix operator+(const matrix& b);
};

template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (T _mat[rows][cols]){
    for (int i=0; i<rows; i++){
        for (int j=0; j<cols; j++){
            mat[i][j] = _mat[i][j];
        }
    }
}

template <class T, int rows, int cols> matrix <T,rows,cols> :: matrix (){
    for (int i=0; i<rows; i++){
        for (int j=0; j<cols; j++){ …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c ×2

c++ ×2

arrays ×1

initialization ×1

malloc ×1

string ×1

strlen ×1