简体   繁体   English

迭代动态分配的char数组

[英]iterate a dynamically allocated char array

I am new to pointers in C, please bear with me. 我是C语言的新手,请多多包涵。 I am trying to write a function which returns the index of the array if the string is found else stores the string and then returns the index. 我正在尝试编写一个函数,如果找到字符串,该函数将返回数组的索引,否则将存储该字符串,然后返回索引。 I want to create a structure like this {"1234", "3241", "2234", "2222"} for which I have dynamically allocated a char array like this (I need to take the size from command line) 我想创建一个像这样的结构{"1234", "3241", "2234", "2222"}为此我动态分配了一个char数组(我需要从命令行获取大小)

char** userToRdrMap = {NULL};
userToRdrMap = malloc(numOfReducers * sizeof(char*));

Now, I have an array of userId's 现在,我有一个userId的数组

char *userId[numOfReducers];
    userId[0] = "2234";
    userId[1] = "2222";
    userId[2] = "3223";
    userId[3] = "2222";

For each userId, I will call a function findRdrNum(userId[i]) which will check the earlier dynamically allocated char array userToRdrMap , if userId is present it should return the index, else store it and then return the index. 对于每个userId,我将调用一个函数findRdrNum(userId[i]) ,该函数将检查较早动态分配的字符数组userToRdrMap ,如果存在userId,则应返回索引,否则将其存储,然后返回索引。 I am not able to proceed with this problems since I am getting confused and lost with pointers. 我无法继续处理此问题,因为我对指针感到困惑和迷茫。 Can anyone please help ? 谁能帮忙吗? This is my program, which tried returning the index and then storing it. 这是我的程序,尝试返回索引然后存储它。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int numOfReducers;
char** userToRdrMap = {NULL};
char* temp1;

int findRdrNum(char *userId){
    if(!userToRdrMap[0]){
        return 0;
    } else{
        int i;
        printf("%s", userToRdrMap[1]);
        for(i=0; i<numOfReducers; i++){
            if(strcmp(userToRdrMap[i], userId))
                return i;
        }
    }
    return NULL;
}

int main (int argc, char *argv[])
{
    numOfReducers = atoi(argv[1]);
    int i;
    char *userId[numOfReducers];
    userId[0] = "2234";
    userId[1] = "2222";
    userId[2] = "3223";
    userId[3] = "2222";
    int rdrNum;

    userToRdrMap = malloc(numOfReducers * sizeof(char*));
/*  temp1 = malloc(numOfReducers * 4 * sizeof(char));
    for (i = 0; i < numOfReducers; i++) {
      userToRdrMap[i] = temp1 + (i * 4);
    }
*/
    printf("%s\n", userId[0]);
    for(i=0; i<numOfReducers; i++){
        rdrNum = findRdrNum(userId[i]);
        strcpy(userToRdrMap[rdrNum], userId[i]);
        printf("%d", rdrNum);
    }
    return 0;
}

Thanks, Harrish 谢谢,哈里希

So basically what your looking for is something like this? 因此,基本上您要找的是这样的东西?

Edit: Fixed minor error in example code 编辑:修复了示例代码中的小错误

int findRdrNum(char *userId) {
    for (int pos = 0; pos < numOfReducers; pos++) 
    // check whether position hasn't been allocated yet
    if (userToRdrMap[pos] != NULL) 
        //compare string and return pos if equal
        if (strcmp(userId, userToRdrMap[pos]) == 0)
            return pos;
}

Also, you could allocate your vector in a function like this: 同样,您可以在这样的函数中分配向量:

int allocateUserToRdrMap(){
    userToRdrMap = malloc(numOfReducers * sizeof(char));
    if (userToRdrMap == NULL)
        return 0;
    return 1;
}

If you are trying to make the function findRdrNum to return the index of the element of userToRdrMap that matches with userId consider that strcmp returns 0 if its arguments are equal; 如果试图使函数findRdrNum返回与userId匹配的userToRdrMap元素的索引,则认为strcmp如果参数相等则返回0;否则,返回0。 therefore your function will retrun the index of the first element that is NOT equal with userId . 因此,您的函数将重新运行与userId不相等的第一个元素的索引。 It will be usefull to check if strcmp(userToRdrMap[i], userId) == 0 . 检查strcmp(userToRdrMap[i], userId) == 0是否有用。 Also, this function has type int so there is no place for that return NULL . 而且,此函数的类型为int因此没有地方可以return NULL Another thing is that it is recommended to the result returned by malloc to your type (malloc returns *void 另一件事是,建议由返回结果malloc你的类型(malloc的回报*void

The Question: 问题:

Your question was a bit confusing, but I could see what you were getting at and it's clear you did put some effort into writing up a decent post. 您的问题有点令人困惑,但我可以看到您的意思,很明显,您确实在写一篇体面的文章上付出了一些努力。 Therefore, I've tried to write a program that accomplishes what you want, and is easy to understand. 因此,我试图编写一个可以实现您想要的并且易于理解的程序。


Program: 程序:

The following program installs the same example strings you've provided in your example automatically. 以下程序会自动安装示例中提供的示例字符串相同的字符串。 It then reads each argument provided in main's argument vector ( char *argc[] ) to check if it is in there. 然后,它读取main的自变量向量( char *argc[] )中提供的每个自变量,以检查它是否在其中。 If it isn't, it gets installed. 如果不是,则安装它。 Everything is demonstrated with print statements, as you'll see in the example output. 如示例输出所示,所有内容均通过打印语句进行演示。

Output Example: 输出示例:

./a.out 2222 3223 kjd 090 kjd
The User ID "2222" exists at index 1!
The User ID "3223" exists at index 2!
Installed "kjd"!
Installed "090"!
The User ID "kjd" exists at index 4!

Here's the program code. 这是程序代码。 I've tried to comment things so you'll understand what I've done. 我尝试发表评论,以便您了解我的所作所为。 At the bottom I'll include some remarks about your original program and what you can do to try and improve it. 在底部,我将对您的原始程序以及您可以做些什么来尝试和改进它进行一些说明。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

// An array of strings: (A pointer to an array of pointers).
// Declaring a variable out in global scope is always initialized to NULL!
char **strings;

// 1: The index of the next free pointer. 2: The total number of pointers available.
int str_idx, str_size;

// Returns index of given string pointer `sp`. If it's not there, -1 is returned.
int indexOf (char *sp) {

    for (int i = 0; i < str_idx; i++) {
        // If string at index i == string we're looking for.
        if (strcmp(sp, strings[i]) == 0) {
            return i;
        }
    }

    return -1;
}

// Copies given string into strings. If necessary, strings is resized.
void installString (char *sp) {
    char *copy = NULL;

    // 1. Ensure we have space. Otherwise resize strings array.
    if (str_idx >= str_size) {
        str_size = str_size * 2;
        strings = realloc(strings, str_size * sizeof(char *));
    }

    // 2. Allocate space for copy of string. Print an error if it failed.
    copy = malloc(strlen(sp) * sizeof(char));
    if (copy == NULL) {
        printf("Error: Allocation failure in \"installString\"!\n");
        exit(EXIT_FAILURE);
    }

    // 3. Copy the contents over.
    copy = strcpy(copy, sp);

    // 4. Place the pointer (copy) at str_idx (next available spot), and post-increment str_idx.
    strings[str_idx++] = copy;
}

int main (int argc, char *argv[]) {

    // 1. Initialize our global strings array. Ensure it succeeded.
    str_size = 10;
    strings = malloc(str_size * sizeof(char *));
    if (strings == NULL) {
        printf("Error: Allocation failure in \"main\"!\n");
        exit(EXIT_FAILURE);
    }

    // 2. Install some example User IDs.
    installString("2234");
    installString("2222");
    installString("3223");
    installString("2222");

    // 3. Check the User IDs provided as program arguments.
    // (I subtract from argc first because argument zero is the name of the program)
    while (--argc) {
        char *id = *(++argv); // Increment argv pointer (to skip program name), dereference at next argument.

        // 4. If the id is installed, print the index. Otherwise install it.
        int index;
        index = indexOf(id);
        if (index > -1) {
            printf("The User ID \"%s\" exists at index %d!\n", id, index);
        } else {
            installString(id);
            printf("Installed \"%s\"!\n", id);
        }
    }

    // 5. Clean up allocated memory.
    for (int i = 0; i < str_idx; i++) {
        free(strings[i]);
    }
    free(strings);

    return EXIT_SUCCESS;
}

Tips: 提示:

  1. The statement: char** userToRdrMap = {NULL}; 语句: char** userToRdrMap = {NULL}; is better written as just char **userToRdrMap; 最好只写成char **userToRdrMap; if you're keeping it in the global scope. 如果您将其保留在全球范围内。 The reason being is that it will automatically be NULL initialized there. 原因是它将在那里自动初始化为NULL。 This isn't true if it's a local or automatic variable though! 但是,如果它是局部变量或自动变量,则不是这样!

  2. Don't return zero as a bad index. 不要将零作为错误索引返回。 Zero is a valid index, and -1 makes a lot more sense because nothing can really be at index -1. 零是一个有效的索引,而-1更有意义,因为在索引-1上什么也没有。

  3. Your function findRdrNum says it returns an int . 您的函数findRdrNum说它返回一个int Yet at the end you return NULL , which is typically used for pointers. 但最后您返回NULL ,通常用于指针。 This is inconsistent. 这是不一致的。 Don't do it. 不要这样

  4. You're not freeing any memory you're allocating in your program. 您不会释放要在程序中分配的任何内存。 You really ought to do this. 您确实应该这样做。

  5. You allocate an array of string pointers in your program. 您在程序中分配一个字符串指针数组。 But you don't actually allocate any space for the strings you're trying to copy to the pointers. 但是实际上,您没有为要复制到指针的字符串分配任何空间。 This is undefined behavior and unacceptable. 这是未定义的行为,是不可接受的。 If you're going to copy anything to the array of pointers you allocated, you need to actually allocate memory for the string you wish to copy, then set the value of the pointer within the strings array to that of the allocated copy. 如果要将任何内容复制到分配的指针数组,则需要为要复制的字符串实际分配内存,然后将字符串数组中的指针值设置为分配的副本的值。 I do this in my example. 我在我的示例中这样做。

Your question is a little unclear as to what your ultimate goal is, but it looks like you wish to read user IDs from stdin (or a file) and add the user IDs to a dynamically expanding array of pointers. 关于最终目标是什么,您的问题尚不清楚,但是您似乎希望从stdin (或文件)中读取用户ID,并将用户ID添加到动态扩展的指针数组中。 While doing this you appear to want to insure that only new IDs are added and all duplicate IDs are skipped. 这样做时,您似乎想确保仅添加新的ID,并跳过所有重复的ID。

While there is nothing wrong with using and array of pointers to char (technically a pointer-to-pointer-to-char ), if all your IDs are of a fixed number of characters, you can greatly simplify your memory allocation by using a pointer-to-array (eg char (*users)[NCHR] ) as the basis for your storage. 尽管使用和指向char的指针数组(从技术上来说,是一个指向 char的指针)没有任何问题,但是,如果您所有的ID都是固定数量的字符,则可以通过使用指针来大大简化内存分配到数组 (例如char (*users)[NCHR] )作为存储的基础。 (where storage can be managed and freed in a single call rather than allocating pointers and storage for IDs separately) However since you look like you want a char ** as the basis for your storage scheme (and it is something you will commonly use anyway), that will be addressed. (可以在单个调用中管理和释放存储空间,而不必分别为ID分配指针和存储空间)。但是,由于您似乎希望将char **作为存储方案的基础(无论如何,通常都会使用它) ),将予以解决。

When looking to store anything in a dynamic fashion, using a pointer-to-pointer is a normal basis for doing so. 当寻求以动态方式存储任何内容时,使用指针到指针是这样做的正常基础。 The scheme is simple. 该方案很简单。 Allocate some reasonably anticipated number of pointers initially, then allocate storage to hold whatever each of your pointers points to, and when you have used up your initial number of pointers, just realloc the number of pointers and keep going. 分配指针的一些合理预计数开始,然后分配存储空间来保存任何您的每一个指针指向,当你用你的指针的初始数量,只是realloc指针的数量和继续下去。 (you can add whatever number of pointers you like each time you reallocate, through doubling the number is a fairly common scheme) (您可以在每次重新分配时添加任意数量的指针,通过增加数量是一种很常见的方案)

To put all that together, let's start out with two simple functions. 综上所述,让我们从两个简单的函数开始。 One to find the user index in the collection of users (if it exists) and return the index (or say -1 if the ID does not exist). 一种在用户集合中查找用户索引(如果存在)并返回索引(如果ID不存在,则返回-1 )。 You could do that as follows: 您可以按照以下步骤进行操作:

/* simple function to check if user exists & return index */
int finduserndx (char **users, char *u, int n)
{
    int i;

    for (i = 0; i < n; i++)             /* loop over each index */
        if (strcmp (users[i], u) == 0)  /* compare IDs as strings */
            return i;                   /* return index on match */

    return -1;  /* return -1 indicating no-match */
}

You simply pass a copy of your collection of users, the new user you wish to add, and the number that exist, then loop over each calling strcmp against the new user and return either the index where it already exists or -1 to indicate it doesn't exist in the list. 您只需传递用户集合,您要添加的新用户以及存在的号码的副本,然后针对新用户遍历每个调用strcmp ,并返回已经存在的索引或-1来指示它列表中不存在。 ( note: if your user IDs are all numbers, it is much more efficient to store them a decimal values) The function will be used in your adduser function. 请注意:如果您的用户ID是全数字,则将它们存储为十进制值会更加有效。)该函数将在adduser函数中使用。

To add a new user, you call finduserndx , and if the user already exists, you are done. 要添加新用户,请调用finduserndx ,如果该用户已经存在,则操作完成。 If it doesn't exists, you need to first check if you have used up all your allocated pointers, and if so, realloc more (always assigning the return of realloc to a temporary pointer), and then allocate storage for new user and copy the new user to the new block of memory that is assigned to the next available pointer in your list. 如果不存在的话,你需要首先检查是否已用完所有分配的指针,如果是的话, realloc更多(总分配的收益realloc到一个临时指针),然后为新用户分配存储和复制新用户到分配给列表中下一个可用指针的新内存块。 You could do something like: 您可以执行以下操作:

/* simple function to add user 'u' to 'users' with '*n' existing users,
 * and '*nptrs' allocated pointers in 'users'. reallocate if
 * '*n + 1 == *nptrs' and allocate for new `users[n]`, increment
 * '*n' and '*nptrs' accordingly. returns beginning address to `users`
 * which must be assigned in caller to prevent becomming a 3-star
 * programmer (not a compliment)
 */
char **adduser (char **users, char *u, int *n, int *nptrs)
{
    if (finduserndx (users, u, *n) != -1) { /* if users exists, return */
        printf ("user: %s ==> duplicate\n", u); /* informational only */
        return users;
    }
    printf ("user: %s --- adding\n", u);    /* informational only */

    if (*n + 1 == *nptrs) { /* check if num pointers exhausted */
        /* realloc using temporary pointer */
        void *tmp = realloc (users, *nptrs * 2 * sizeof *users);
        if (!tmp) { /* validate realloc success/handle failure */
            perror ("realloc - memory exhausted");
            exit (EXIT_FAILURE);
        }
        users = tmp;    /* assign new block to users */
        *nptrs *= 2;    /* update number of allocated pointers */
    }

    users[*n] = malloc (strlen (u) + 1);    /* allocate for new user */
    if (!users[*n]) {   /* vallidate malloc/handle failure */
        perror ("malloc users[n] - memory exhausted");
        exit (EXIT_FAILURE);
    }
    strcpy (users[(*n)++], u);  /* copy new user to users[n] & increment */

    return users;   /* return pointer to start of users */
}

( note: if realloc fails, your existing data is not lost and still exists and is available through the original pointer -- so your handling of a realloc failure does not need to be an immediate exit -- but that will add a bit of complexity better left for later) 注意:如果realloc失败,您的现有数据不会丢失并且仍然存在,并且可以通过原始指针访问-因此您对realloc失败的处理并不需要立即exit -但这会增加一些复杂性最好留待以后)

( also note: how the number of current user IDs ( 'n' ) and the current number of allocated pointers ( 'nptrs' ) are passed as pointers so that when their value is updated in the function -- the new value is available back in the calling function) 另请注意:如何将当前用户ID的数量( 'n' )和当前分配的指针的数量( 'nptrs' )作为指针传递,以便在函数中更新其值时,可以返回新值在调用函数中)

That is the nuts-and-bolts of your storage scheme. 那就是您的存储方案的基本要素。 Now all you need to do in the caller ( main() here) is to read each user ID, get the length, trim the trailing '\\n' (so strcmp works -- and so you don't have spurious '\\n' s dangling off the end of your strings), and then call adduser passing the string as an argument along with pointers to the current number if user IDs and a pointer to the current number of allocated pointers. 现在,您在调用方( main()此处)所需要做的就是读取每个用户ID,获取长度,修剪尾随的'\\n' (这样strcmp可以正常工作-因此您不会产生虚假的'\\n'悬在字符串末尾),然后调用adduser ,将字符串作为参数以及指向当前数字的指针(如果有用户ID)和指向当前已分配指针的指针传递给参数。

Putting it altogether, you could do something like the following: 综上所述,您可以执行以下操作:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NREDUCR 4   /* if you need constants, define them */
#define MAXC  128   /* (don't use magic numbers in code) */

/* simple function to check if user exists & return index */
int finduserndx (char **users, char *u, int n)
{
    int i;

    for (i = 0; i < n; i++)             /* loop over each index */
        if (strcmp (users[i], u) == 0)  /* compare IDs as strings */
            return i;                   /* return index on match */

    return -1;  /* return -1 indicating no-match */
}

/* simple function to add user 'u' to 'users' with '*n' existing users,
 * and '*nptrs' allocated pointers in 'users'. reallocate if
 * '*n + 1 == *nptrs' and allocate for new `users[n]`, increment
 * '*n' and '*nptrs' accordingly. returns beginning address to `users`
 * which must be assigned in caller to prevent becomming a 3-star
 * programmer (not a compliment)
 */
char **adduser (char **users, char *u, int *n, int *nptrs)
{
    if (finduserndx (users, u, *n) != -1) { /* if users exists, return */
        printf ("user: %s ==> duplicate\n", u); /* informational only */
        return users;
    }
    printf ("user: %s --- adding\n", u);    /* informational only */

    if (*n + 1 == *nptrs) { /* check if num pointers exhausted */
        /* realloc using temporary pointer */
        void *tmp = realloc (users, *nptrs * 2 * sizeof *users);
        if (!tmp) { /* validate realloc success/handle failure */
            perror ("realloc - memory exhausted");
            exit (EXIT_FAILURE);
        }
        users = tmp;    /* assign new block to users */
        *nptrs *= 2;    /* update number of allocated pointers */
    }

    users[*n] = malloc (strlen (u) + 1);    /* allocate for new user */
    if (!users[*n]) {   /* vallidate malloc/handle failure */
        perror ("malloc users[n] - memory exhausted");
        exit (EXIT_FAILURE);
    }
    strcpy (users[(*n)++], u);  /* copy new user to users[n] & increment */

    return users;   /* return pointer to start of users */
}

int main (int argc, char **argv) {

    /* allocate number of pointer given as argument (NREDUCR by default) */
    int nptrs = argc > 1 ? (int)strtol(argv[1], NULL, 0) : NREDUCR,
        ndx = 0, i;
    char user[MAXC] = "";   /* fixed buffer for reading input */
    char **users = NULL;    /* pointer to pointer to char */

    /* allocate/validate initial number of pointers */
    users = malloc (nptrs * sizeof *users);
    if (!users) {
        perror ("malloc - users");
        exit (EXIT_FAILURE);
    }

    while (fgets (user, MAXC, stdin)) {     /* read each ID from stdin */
        size_t len = strlen (user);         /* get length of ID */
        if (len && user[len - 1] == '\n')   /* check last char is '\n' */
        user[--len] = 0;                    /* overwrite w/nul-character */
        else if (len - 1 == MAXC) {         /* test if ID too long */
            fprintf (stderr, "error: ID too long.\n");
            exit (EXIT_FAILURE);
        }
        /* call adduser assigning return to users */
        users = adduser (users, user, &ndx, &nptrs);
    }

    putchar ('\n');         /* output stored user IDs */
    for (i = 0; i < ndx; i++) {
        printf ("user[%2d] : %s\n", i, users[i]);
        free (users[i]);    /* freeing storage as you go */
    }
    free (users);           /* free pointers */

    return 0;
}

Example Input ID's (with duplicates) 输入ID示例(重复)

$ cat dat/userids.txt
1993
2947
2234
2222
3223
1016
1444
1125
1194
2234
2732
2679
2222
2681
1444
1629

Example Use/Output 使用/输出示例

$ ./bin/addusers_dyn <dat/userids.txt
user: 1993 --- adding
user: 2947 --- adding
user: 2234 --- adding
user: 2222 --- adding
user: 3223 --- adding
user: 1016 --- adding
user: 1444 --- adding
user: 1125 --- adding
user: 1194 --- adding
user: 2234 ==> duplicate
user: 2732 --- adding
user: 2679 --- adding
user: 2222 ==> duplicate
user: 2681 --- adding
user: 1444 ==> duplicate
user: 1629 --- adding

user[ 0] : 1993
user[ 1] : 2947
user[ 2] : 2234
user[ 3] : 2222
user[ 4] : 3223
user[ 5] : 1016
user[ 6] : 1444
user[ 7] : 1125
user[ 8] : 1194
user[ 9] : 2732
user[10] : 2679
user[11] : 2681
user[12] : 1629

Memory Use/Error Check 内存使用/错误检查

In any code you write that dynamically allocates memory, you have 2 responsibilities regarding any block of memory allocated: (1) always preserve a pointer to the starting address for the block of memory so, (2) it can be freed when it is no longer needed. 在您编写的任何可以动态分配内存的代码中,对于任何分配的内存块,您都有2个责任 :(1) 始终保留指向该内存块起始地址的指针,因此,(2)在没有内存块时可以将其释放需要更长的时间。

It is imperative that you use a memory error checking program to insure you do not attempt to access memory or write beyond/outside the bounds of your allocated block, attempt to read or base a conditional jump on an uninitialized value, and finally, to confirm that you free all the memory you have allocated. 必须使用一个内存错误检查程序来确保您不尝试访问内存或不在分配的块的边界之外/之外进行写入,不要尝试在未初始化的值上读取或建立条件跳转,最后确定您可以释放已分配的所有内存。

For Linux valgrind is the normal choice. 对于Linux, valgrind是通常的选择。 There are similar memory checkers for every platform. 每个平台都有类似的内存检查器。 They are all simple to use, just run your program through it. 它们都很容易使用,只需通过它运行程序即可。

$ valgrind ./bin/addusers_dyn <dat/userids.txt
==26867== Memcheck, a memory error detector
==26867== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==26867== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==26867== Command: ./bin/addusers_dyn
==26867==
user: 1993 --- adding
user: 2947 --- adding
user: 2234 --- adding
user: 2222 --- adding
user: 3223 --- adding
user: 1016 --- adding
user: 1444 --- adding
user: 1125 --- adding
user: 1194 --- adding
user: 2234 ==> duplicate
user: 2732 --- adding
user: 2679 --- adding
user: 2222 ==> duplicate
user: 2681 --- adding
user: 1444 ==> duplicate
user: 1629 --- adding

user[ 0] : 1993
user[ 1] : 2947
user[ 2] : 2234
user[ 3] : 2222
user[ 4] : 3223
user[ 5] : 1016
user[ 6] : 1444
user[ 7] : 1125
user[ 8] : 1194
user[ 9] : 2732
user[10] : 2679
user[11] : 2681
user[12] : 1629
==26867==
==26867== HEAP SUMMARY:
==26867==     in use at exit: 0 bytes in 0 blocks
==26867==   total heap usage: 16 allocs, 16 frees, 289 bytes allocated
==26867==
==26867== All heap blocks were freed -- no leaks are possible
==26867==
==26867== For counts of detected and suppressed errors, rerun with: -v
==26867== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Always confirm that you have freed all memory you have allocated and that there are no memory errors. 始终确认已释放已分配的所有内存,并且没有内存错误。

Look things over and let me know if you have further questions or if I missed the intent of your question. 仔细检查一下,如果您还有其他问题或想念您的问题,请告诉我。 I'm happy to help further if you can clarify what additional you need. 如果您能澄清所需的其他内容,我们很乐意为您提供进一步的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 迭代动态分配的数组 - Iterate a Dynamically Allocated Array 从结构初始化为动态分配的char数组 - initialize to dynamically allocated char array from a struct 将值从静态char数组分配给动态分配的char数组 - Assigning values from a static char array to a dynamically allocated char array strcpy一个static的char数组到一个动态分配的char数组中保存memory - Strcpy a static char array into a dynamically allocated char array to save memory 将行读入动态分配的char指针数组时出现段错误 - Seg fault when reading a line into dynamically allocated char pointer array 如何在C中将fprintf与动态分配的无符号char *数组一起使用 - How to use fprintf with a dynamically allocated unsigned char* array in C 如何从 C 中动态分配的字符数组中分析字符串 - How to analyze strings from a dynamically allocated char array in C 修改动态分配的char*二维数组的函数 - Function to modify dynamically allocated two dimensional array of char* char *在结构中,指向char数组,然后使用strncpy。 尝试避免动态分配内存 - char * in a struct, pointing to a char array, then using strncpy. Trying to avoid dynamically allocated memory 动态分配的动态分配字符串数组 - Dynamically allocated array of dynamically allocated strings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM