使用 malloc 时出错

2023-12-11

I pass char ** input from main() to processInExp()函数,然后我再次传递它processInExp()功能为getInput()函数在读取文件时动态分配它。

Inside getInput()功能input检查时已正确分配内存,但在使用时in processInExp()它遇到运行时错误。可能是什么问题?

下面是我的代码:

int getInput(char ** input, const char * fileName)
{
    int numInput = 0;
    int i, j;
    char c;
    char tempInput[100];
    FILE * pFile;
    if((pFile = fopen(fileName, "r")) == NULL)
    {
        printf("Cannot read file %s\n", fileName);
        system("PAUSE");
        exit(1);
    }
    while(!feof(pFile))
    {
        c = fgetc(pFile);
        if(c == '\n') ++numInput;

    }
    /* printf("%d\n", numInput); */
    input = (char**)malloc(numInput * sizeof(char*)); /* #2 MALLOC input */
    rewind(pFile);
    for(i = 0; !feof(pFile); ++i)
    {
        fscanf(pFile, "%[^\n]%*c", tempInput);
        /* printf("%s\n", tempInput); */
        input[i] = (char*)malloc((strlen(tempInput) + 1) * sizeof(char)); /* #3 MALLOC input[] */
        strcpy(input[i], tempInput);
        /* printf("%s\n", input[i]); */ /* #4 PRINT OUT PERFECTLY */
        memset(tempInput, 0, sizeof(tempInput));
    }
    fclose(pFile);
    return numInput;
}
void processInExp(char ** input, char ** output, const char * fileName)
{
    int numFormula;
    int i;

    numFormula = getInput(input, fileName); /* #1 PASSING input */
    /* printf("%s\n", input[0]); */ /* #5 RUNTIME ERROR */
    output = (char**)malloc(numFormula * sizeof(char*));
    system("PAUSE");

    for(i = 0; i < numFormula; ++i)
    {
        convertIntoPost(input[i], output[i]);
        printf("%d. %s -> %s", (i + 1), input[i], output[i]);
    }

}

虽然其他人指出了按值传递的问题,但还有另一个可以发生学习的问题。无需预先读取文件以确定字符数或行数,然后倒带文件以读取每一行。

看一眼getline which 返回读取的字符数。您需要做的就是保留一个sum变量并在读取所有行后,只需返回(或更新您作为参数提供的指针)即可完成。当然你也可以这样做fscanf or fgets通过致电strlen读完该行后。

以下是一次读取文本文件并确定字符数的简短示例(不带newline)并将该信息返回给调用函数。正如您需要将指针传递给指针数组一样getInput,我们将使用作为参数传递的指针来返回line and character计入我们的调用函数。如果您声明并调用函数来读取文件,如下所示:

size_t nline = 0;       /* placeholders to be filled by readtxtfile */
size_t nchar = 0;       /* containing number of lines/chars in file */
...
char **file = readtxtfile (fn, &nline, &nchar);

通过在调用函数中声明变量,然后将指向变量的指针作为参数传递(使用 urnary&),您可以更新函数中的值,并让这些值可以重新在函数中使用main(或者你调用的任何函数readtxtfile from.)

说明这些点的一个简单示例可能是:

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

#define NMAX 256

char **readtxtfile (char *fn, size_t *idx, size_t *sum);
void prn_chararray (char **ca);
void free_chararray (char **ca);

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

    size_t nline = 0;       /* placeholders to be filled by readtxtfile */
    size_t nchar = 0;       /* containing number of lines/chars in file */
    char *fn = argc > 1 ? argv[1] : NULL;/* if fn not given, read stdin */

    /* read each file into an array of strings,
     * number of lines/chars read updated in nline, nchar
     */
    char **file = readtxtfile (fn, &nline, &nchar);

    /* output number of lines read & chars read and from where  */
    printf ("\n read '%zu' lines & '%zu' chars from file: %s\n\n", 
            nline, nchar, fn ? fn : "stdin");

    /* simple print function to print all lines */
    if (file) prn_chararray (file);

    /* simple free memory function */
    if (file) free_chararray (file);

    return 0;
}

/* simple function using getline to read any text file and return
 * the lines read in an array of pointers. user is responsible for
 * freeing memory when no longer needed
 */
char **readtxtfile (char *fn, size_t *idx, size_t *sum)
{
    char *ln = NULL;                /* NULL forces getline to allocate  */
    size_t n = 0;                   /* line buf size (0 - use default)  */
    ssize_t nchr = 0;               /* number of chars actually read    */
    size_t nmax = NMAX;             /* check for reallocation           */
    char **array = NULL;            /* array to hold lines read         */
    FILE *fp = NULL;                /* file pointer to open file fn     */

    /* open / validate file or read stdin */
    fp = fn ? fopen (fn, "r") : stdin;
    if (!fp) {
        fprintf (stderr, "%s() error: file open failed '%s'.", __func__, fn);
        return NULL;
    }

    /* allocate NMAX pointers to char* */
    if (!(array = calloc (NMAX, sizeof *array))) {
        fprintf (stderr, "%s() error: memory allocation failed.", __func__);
        return NULL;
    }

    /* read each line from stdin - dynamicallly allocated   */
    while ((nchr = getline (&ln, &n, fp)) != -1)
    {
        /* strip newline or carriage rtn    */
        while (nchr > 0 && (ln[nchr-1] == '\n' || ln[nchr-1] == '\r'))
            ln[--nchr] = 0;

        *sum += nchr;               /* add chars in line to sum         */

        array[*idx] = strdup (ln);  /* allocate/copy ln to array        */

        (*idx)++;                   /* increment value at index         */

        if (*idx == nmax) {         /* if lines exceed nmax, reallocate */
            char **tmp = realloc (array, nmax * 2);
            if (!tmp) {
                fprintf (stderr, "%s() error: reallocation failed.\n", __func__);
                exit (EXIT_FAILURE); /* or return NULL; */
            }
            array = tmp;
            nmax *= 2;
        }
    }

    if (ln) free (ln);              /* free memory allocated by getline */
    if (fp != stdin) fclose (fp);   /* close open file descriptor       */

    return array;
}

/* print an array of character pointers. */
void prn_chararray (char **ca)
{
    register size_t n = 0;
    while (ca[n])
    {
        printf (" arr[%3zu]  %s\n", n, ca[n]);
        n++;
    }
}

/* free array of char* */
void free_chararray (char **ca)
{
    if (!ca) return;
    register size_t n = 0;
    while (ca[n])
        free (ca[n++]);
    free (ca);
}

使用/输出

$ ./bin/getline_ccount <dat/fc-list-fonts.txt

 read '187' lines & '7476' chars from file: stdin

 arr[  0]  andalemo.ttf: Andale Mono - Regular
 arr[  1]  arialbd.ttf: Arial - Bold
 arr[  2]  arialbi.ttf: Arial - Bold Italic
 arr[  3]  ariali.ttf: Arial - Italic
 arr[  4]  arialnbi.ttf: Arial
 arr[  5]  arialnb.ttf: Arial
 arr[  6]  arialni.ttf: Arial
 arr[  7]  arialn.ttf: Arial
 arr[  8]  arial.ttf: Arial - Regular
 arr[  9]  ARIALUNI.TTF: Arial Unicode MS - Regular
 arr[ 10]  ariblk.ttf: Arial
 arr[ 11]  Bailey Script Regular.ttf: Bailey Script - Regular
 arr[ 12]  Bailey_Script_Regular.ttf: Bailey Script - Regular
 arr[ 13]  Belwe Gotisch.ttf: Belwe Gotisch - Regular
 arr[ 14]  Belwe_Gotisch.ttf: Belwe Gotisch - Regular
 <snip>

内存/泄漏检查

每当您在代码中分配/释放内存时,请不要忘记使用内存检查器来确保代码中没有内存错误或泄漏:

$ valgrind ./bin/getline_ccount <dat/fc-list-fonts.txt
==20259== Memcheck, a memory error detector
==20259== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==20259== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==20259== Command: ./bin/getline_readfile_function
==20259==

 read '187' line from file: stdin

 arr[  0]  andalemo.ttf: Andale Mono - Regular
 arr[  1]  arialbd.ttf: Arial - Bold
 arr[  2]  arialbi.ttf: Arial - Bold Italic
 arr[  3]  ariali.ttf: Arial - Italic
<snip>

==20259==
==20259== HEAP SUMMARY:
==20259==     in use at exit: 0 bytes in 0 blocks
==20259==   total heap usage: 189 allocs, 189 frees, 9,831 bytes allocated
==20259==
==20259== All heap blocks were freed -- no leaks are possible
==20259==
==20259== For counts of detected and suppressed errors, rerun with: -v
==20259== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

关注评论

您在评论中发布的代码存在几个问题:

for(i = 0; !feof(pFile); ++i) {
    fscanf(pFile, "%[^\n]%*c", tempInput); 
    /* printf("%s\n", tempInput); */ 
    input[i] = (char*)malloc((strlen(tempInput) + 1) * sizeof(char)); 
    strcpy(input[i], tempInput); 
    printf("%s\n", input[i]); 
    memset(tempInput, 0, sizeof(tempInput)); 
} 
    for(i = 0; i < numInput; ++i) {
    convertIntoPost(input[i], output[i]);
}

首先,阅读第一条评论中的链接了解原因feof使用它来指示循环中的 EOF 时可能会导致问题。二、功能有return values,利用它们获得优势的能力告诉您是否在工作中使用了正确的功能。

您在尝试硬塞阅读整行内容时遇到的困难fscanf应该告诉你一些事情......你通过选择格式说明符而陷入的问题"%[^\n]%*c"读取包含以下内容的行whitespace是确切的原因fscanf不是适合这项工作的工具。

为什么?这scanf创建函数系列来读取discrete价值观。他们的return是基于:

成功匹配和分配的输入项的数量

使用格式说明符,成功读取的项目数为1. The *%c读取并丢弃newline,但不会添加到项目计数中。当尝试读取可能包含空行的文件时,这会导致一个大问题。然后会发生什么?你经历了一个input failure and fscanf回报0——但这仍然是一条非常有效的路线。当发生这种情况时,不会读取任何内容。您无法检查退货是否为>= 0因为当你遇到空行时,你就会永远循环......

使用格式说明符,您无法检查EOF任何一个。为什么?随着scanf函数族:

价值EOF如果返回end of input到达了before要么first successful conversion or a matching failure发生。

这在你的情况下永远不会发生,因为你有一个input failure with fscanf (not end of input) 和不matching failure已经发生了。你开始明白为什么了吗fscanf可能不是适合这项工作的工具?

C 库提供了两个函数line-oriented输入。他们是fgets and getline。两者都将整行文本读入行缓冲区。这将包括newline每行末尾(包括空行)。因此,当您使用其中任何一个来阅读文本时,最好删除newline通过覆盖null-terminating特点。

使用哪个?和fgets,您可以通过适当调整字符缓冲区的大小来限制读取的字符数。getline现在是 C 库的一部分,它提供了返回实际读取的字符数的额外好处(额外的好处),但无论该行有多长,它都会读取该行,因为它会为您动态分配缓冲区。我更喜欢它,但只知道您需要检查它已读取的字符数。

由于我提供了getline上面的例子,你的读循环可以更好地写成fgets如下:

    while (fgets (tempInput, MAXL, pFile) != NULL) {
        nchr = strlen (tempInput);
        while (nchr && (tempInput[nchr-1] == '\n' || tempInput[nchr-1] == '\r'))
            tempInput[--nchr] = 0;     /* strip newlines & carriage returns */
        input[i++] = strdup (tempInput);    /* allocates & copies tempInput */
    }
    numInput = i;

接下来,您的分配不需要转换为(char *)。返回的malloc and calloc只是指向分配的内存块(即地址)的指针。 (无论你为什么分配内存,它都是一样的)没有必要sizeof (char)。总是1。所以只需写:

input[i] = malloc (strlen(tempInput) + 1); 
strcpy (input[i], tempInput);

两者都更方便的方式allocate and copy正在使用strdup. With strdup,上面两行就变得简单了:

input[i++] = strdup (tempInput);    /* allocates & copies */

接下来就不需要了memset.

memset(tempInput, 0, sizeof(tempInput));

If tempInput声明为可容纳 100 个字符:tempInput[100],您最多可以读取字符串99 char一遍又一遍地进入同一个缓冲区,而无需将内存归零。为什么?蜇伤是null-terminated。你不关心之后缓冲区里有什么null-terminator...

有很多需要考虑的内容。将它们放在一个简短的示例中,您可以执行以下操作:

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

#define MAXL 256

/* dummy function */
void convertIntoPost (char *in, char **out)
{
    size_t i = 0, len = strlen (in);
    *out = calloc (1, len + 1);

    for (i = 0; i < len; i++) {
        (*out)[len-i-1] = in[i];
    }
}

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

    char tempInput[MAXL] = {0};
    char **input = NULL, **output = NULL;
    size_t i = 0, numInput = 0;
    size_t nchr = 0;
    FILE *pFile = NULL;

    pFile = argc > 1 ? fopen (argv[1], "r") : stdin;

    if (!pFile) {
        fprintf (stderr, "error: file open failed '%s'.\n", 
                argv[1] ? argv[1] : "stdin");
        return 1;
    }

    input  = calloc (1, MAXL);  /* allocate MAXL pointer for input & output   */
    output = calloc (1, MAXL);  /* calloc allocates and sets memory to 0-NULL */

    if (!input || !output) {    /* validate allocation */
        fprintf (stderr, "error: memory allocation failed.\n");
        return 1;
    }

    while (fgets (tempInput, MAXL, pFile) != NULL) {
        nchr = strlen (tempInput);
        while (nchr && (tempInput[nchr-1] == '\n' || tempInput[nchr-1] == '\r'))
            tempInput[--nchr] = 0;
        input[i++] = strdup (tempInput);    /* allocates & copies */
    }
    numInput = i;

    fclose (pFile);

    /* call convertIntoPost with input[i] and &output[i] */
    for (i = 0; i < numInput; ++i) {
        convertIntoPost (input[i], &output[i]);
        printf (" input[%2zu]: %-25s  output[%2zu]: %s\n",
                i, input[i], i, output[i]);
    }

    /* free all memory */
    for (i = 0; i < numInput; ++i) {
        free (input[i]), free (output[i]);
    }
    free (input), free (output);

    return 0;
}

示例输出

$ ./bin/feoffix ../dat/captnjack.txt
 input[ 0]: This is a tale             output[ 0]: elat a si sihT
 input[ 1]: Of Captain Jack Sparrow    output[ 1]: worrapS kcaJ niatpaC fO
 input[ 2]: A Pirate So Brave          output[ 2]: evarB oS etariP A
 input[ 3]: On the Seven Seas.         output[ 3]: .saeS neveS eht nO

编译代码的注意事项

Always编译你的代码Warnings已启用。这样编译器可以帮助指出代码可能存在歧义的区域等。要在编译时启用警告,只需添加-Wall and -Wextra到你的编译字符串。 (如果您确实想要所有警告,请添加-pedantic(定义:过度关注琐碎细节))。花时间阅读并理解编译器通过警告告诉您什么(它们真的非常好,您将很快了解每个警告的含义)。然后...去解决问题以便你的代码可以编译without任何警告。

只有非常罕见和有限的情况允许“理解并选择允许”保留警告(例如使用无法访问源代码的库时)

因此,将所有内容放在一起,当您编译代码时,至少应该使用以下内容进行编译以进行测试和开发:

gcc -Wall -Wextra -o progname progname.c -g

With gcc, the -g选项告诉编译器生成额外的调试信息以供调试器使用gdb(学习它)。

当您解决了所有错误并准备好最终编译代码时,您将需要添加优化,例如优化级别-On(这就是资本O[非零] 其中'n'是水平1, 2, or 3 (0为默认值),-Ofast本质上是-O3有一些额外的优化)。您可能还想考虑告诉编译器inline如果可能的话,你的功能-finline-functions以消除函数调用开销。因此,对于最终编译,您将需要类似的内容:

gcc -Wall -Wextra -finline-functions -Ofast -o progname progname.c

优化可以使性能提高 10 倍,并减少程序执行时间(在某些情况下,性能提高 1000%(通常提高 300-500%))。非常值得添加几个开关。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 malloc 时出错 的相关文章

  • boost::asio + std::future - 关闭套接字后访问冲突

    我正在编写一个简单的 TCP 客户端来发送和接收单行文本 异步操作由 std future 处理 以便于超时阻塞查询 不幸的是 我的测试应用程序在破坏服务器对象时因访问冲突而崩溃 这是我的代码 TCP客户端 hpp ifndef TCPCL
  • 用 C++ 进行服装建模 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在编写一些软件 最终会绘制一个人体框架 可以配置各种参数 并且计划是在假人身上放置某种衣服 我研究
  • 如何使用MemoryCache代替Timer来触发一个方法?

    以下方法通过等待已运行操作的结果来处理并发请求 对数据的请求可能会使用相同 不同的凭据同时出现 对于每组唯一的凭据 最多可以有一个GetCurrentInternal呼叫正在进行中 当准备就绪时 该呼叫的结果将返回给所有排队的服务员 pri
  • std::cout 和 std::wcout 有什么区别?

    在c 中 有什么区别std cout and std wcout 它们都控制流缓冲区的输出或将内容打印到控制台 或者它们只是相似吗 它们作用于不同的字符类型 std cout uses char作为字符类型 std wcout uses w
  • Unix网络编程澄清

    我正在翻阅这本经典书籍Unix网络编程 https rads stackoverflow com amzn click com 0139498761 当我偶然发现这个程序时 第 6 8 节 第 179 180 页 include unp h
  • 如何访问另一个窗体上的ListView控件

    当单击与 ListView 所在表单不同的表单中的按钮时 我试图填充 ListView 我在 Form1 中创建了一个方法以在 Form2 中使用 并将参数传递给 Form1 中的方法 然后填充 ListView 当我调试时 我得到了传递的
  • 单击 form2 上的按钮触发 form 1 中的方法

    我对 Windows 窗体很陌生 我想知道是否可以通过单击表单 2 中的按钮来触发表单 1 中的方法 我的表格 1 有一个组合框 我的 Form 2 有一个 保存 按钮 我想要实现的是 当用户单击表单 2 中的 保存 时 我需要检查表单 1
  • PlaySound 可在 Visual Studio 中运行,但不能在独立 exe 中运行

    我正在尝试使用 Visual Studio 在 C 中播放 wav 文件 我将文件 my wav 放入项目目录中并使用代码 PlaySound TEXT my wav NULL SND FILENAME SND SYNC 我按下播放按钮 或
  • 批量更新 SQL Server C#

    我有一个 270k 行的数据库 带有主键mid和一个名为value 我有一个包含中值和值的文本文件 现在我想更新表格 以便将每个值分配给正确的中间值 我当前的方法是从 C 读取文本文件 并为我读取的每一行更新表中的一行 必须有更快的方法来做
  • Visual Studio 中的测试单独成功,但一组失败

    当我在 Visual Studio 中单独运行测试时 它们都顺利通过 然而 当我同时运行所有这些时 有些通过 有些失败 我尝试在每个测试方法之间暂停 1 秒 但没有成功 有任何想法吗 在此先感谢您的帮助 你们可能有一些共享数据 检查正在使用
  • 私有模板函数

    我有一堂课 C h class C private template
  • std::async 与重载函数

    可能的重复 std bind 重载解析 https stackoverflow com questions 4159487 stdbind overload resolution 考虑以下 C 示例 class A public int f
  • C++ 密码屏蔽

    我正在编写一个代码来接收密码输入 下面是我的代码 程序运行良好 但问题是除了数字和字母字符之外的其他键也被读取 例如删除 插入等 我知道如何避免它吗 特q string pw char c while c 13 Loop until Ent
  • 为什么在setsid()之前fork()

    Why fork before setsid 守护进程 基本上 如果我想将一个进程与其控制终端分离并使其成为进程组领导者 我使用setsid 之前没有分叉就这样做是行不通的 Why 首先 setsid 将使您的进程成为进程组的领导者 但它也
  • 如何在 C# 中调整图像大小同时保持高质量?

    我从这里找到了一篇关于图像处理的文章 http www switchonthecode com tutorials csharp tutorial image editing saving cropping and resizing htt
  • Server.MapPath - 给定的物理路径,预期的虚拟路径

    我正在使用这行代码 var files Directory GetFiles Server MapPath E ftproot sales 在文件夹中查找文件 但是我收到错误消息说 给定物理路径但虚拟路径 预期的 我对在 C 中使用 Sys
  • 如何在按钮单击时模拟按键 - Unity

    我对 Unity 中的脚本编写非常陌生 我正在尝试创建一个按钮 一旦单击它就需要模拟按下 F 键 要拾取一个项目 这是我当前的代码 在编写此代码之前我浏览了所有统一论坛 但找不到任何有效的东西 Code using System Colle
  • 英特尔 Pin 与 C++14

    问题 我有一些关于在 C 14 或其他 C 版本中使用英特尔 Pin 的问题 使用较新版本从较旧的 C 编译代码很少会出现任何问题 但由于 Intel Pin 是操作指令级别的 如果我使用 C 11 或 C 14 编译它 是否会出现任何不良
  • 使用 GhostScript.NET 打印 PDF DPI 打印问题

    我在用GhostScript NET http ghostscriptnet codeplex com打印 PDF 当我以 96DPI 打印时 PDF 打印效果很好 但有点模糊 如果我尝试以 600DPI 打印文档 打印的页面会被极大地放大
  • 当另一个线程可能设置共享布尔标志(最多一次)时,是否可以读取共享布尔标志而不锁定它?

    我希望我的线程能够更优雅地关闭 因此我尝试实现一个简单的信号机制 我不认为我想要一个完全事件驱动的线程 所以我有一个工作人员有一种方法可以使用关键部分优雅地停止它Monitor 相当于C lock我相信 绘图线程 h class Drawi

随机推荐

  • 获取php中的referrer URL(包括参数)

    是否有任何 HTTP 标头可供我使用网络服务器 服务器端脚本来获取整个引荐来源网址 包括查询字符串等 您应该能够从 SERVER HTTP REFERER 变量中获取它
  • 使用 Flutter API 加密读取 PEM 文件

    import package encrypt encrypt dart import package encrypt encrypt io dart import dart io import package pointycastle as
  • ZedGraph 用图表线平滑移动 Y2Axis

    在回答我的问题时 ZedGraph 自定义图表 我有每秒插入数据的图表 现在我有其他问题 如何用图表线平滑地向下移动Y2轴 DateTime类型 并在图表中始终只显示最后30分钟 如何格式化 Y2Axis 标签 HH mm 以获得 10 0
  • 返回类型:If 在函数中条件调用 sys.exit()

    假设我在控制台脚本 1 中有以下函数 def example x int gt typing Union typing NoReturn int if x gt 10 something is wrong if this condition
  • 如何防止创建两个字段值相同的记录?

    我有下表 CREATE TABLE people first name VARCHAR 128 NOT NULL nick name VARCHAR 128 NULL 我想防止人们在尝试插入时将昵称与名字相同 我不想在任一列上创建索引 只是
  • Java 同步和可重入锁定

    当我们同步一个对象时 这是一个可重入锁吗 同步锁和可重入锁之间有真正的区别吗 亲切的问候 是的 锁定synchronized关键字是可重入的 但它们之间的实现可能有所不同 例如 在 JVM 的早期版本中 ReentrantLock的实现比s
  • 如果 knit root.dir 更改,knitr::include_graphics() 无法找到文件

    knitr允许您通过更改来更改评估代码块的目录root dir option r setup include FALSE knitr opts knit set root dir Project 这也可以在 RStudio 的全局选项中更改
  • 文本视图行 - 建议

  • 如何更改控制器中的 $model->attributes 值 - Yii

    用户主控制器代码 public function actionUpdate id model this gt loadModel id if isset POST UserMaster model gt attributes POST Us
  • arm-linux-androideabi-g++:-fuse-linker-plugin,但找不到 liblto_plugin.so

    我在ubuntu 12 04下编译Chrome V8时遇到一个问题是 arm linux androideabi g 致命错误 fuse linker plugin 但找不到 liblto plugin so ndk版本是r8b 我怎么解决
  • 了解使用 Photoshop 生成的 24 位 PNG

    具有透明度的 24 位 png 文件 可以使用以下命令生成Photoshop 真的有 24 位分布在每种颜色加上 alpha 上吗 或者 24 位仅指颜色并忽略 alpha RGBA 8888 有没有工具可以检查 PNG 文件并验证此类信息
  • 具有多个图像的 Pod

    创建一个名为 xyz 的 pod 其中包含一个容器 用于在其中运行以下每个映像 指定的映像可能在 1 到 4 个之间 nginx redis Memcached consul 问题不太清楚 但假设您希望一个 Pod 具有多个容器 下面是可以
  • 错误:结果不是以下位置的数据框:

    我正在尝试在相当大的数据框上运行拟合函数 该数据框由名为的变量分组 big group and small group 特别是 我试图获得每个的预测和 coefs 值small group代替big group 也就是说 我试图将这些新列添
  • 有没有什么好的方法来加密C#桌面应用程序[重复]

    这个问题在这里已经有答案了 可能的重复 保护 NET 代码免遭逆向工程 我们只是用C winforms开发一个应用程序 有什么好的加密方法可以帮助我们防止盗版吗 我看到有些软件可能需要硬件支持来保护其软件 如何实现 提前致谢 好吧 你在这里
  • 不读取模型[关闭]

    Closed 这个问题需要调试细节 目前不接受答案 我正在用Python编写一个程序 我想连接GPT4ALL 以便该程序像GPT聊天一样工作 仅在我的编程环境中本地运行 为此 我已经安装了 GPT4All 13B snoozy ggmlv3
  • 在 javascript 警报中编写 php

    我用以下方式在JS中编写PHP alert echo Error login 关联一个xml 用symfony翻译成两种语言 但现在不起作用 我该如何解决 您缺少引号alert call alert
  • Ruby on Rails - 将模型中的字段添加到另一个模型的表单上

    我有两个型号Contract and Addendum 合同has many addendums和附录belongs to contract 创建新合同时 将自动创建新的附录 但需要一些额外的元素来创建新的附录 如何添加字段value 这是
  • Pandas 中的顺序组内枚举

    假设我有以下数据框 date A B C D 0 2014 03 20 1 561714 0 979202 0 454935 0 629215 1 2014 03 20 0 390851 0 045697 1 683257 0 771027
  • 将引用(工具>引用)与 VBA 代码(宏)连接

    我想使用 VBA 代码以编程方式将一些引用连接到我的 VBA 项目 即无需使用 工具 gt 引用 手动设置引用 这可能吗 例如 Microsoft Office 12 0 对象库 您没有提到 Office 应用程序 在 MS Access
  • 使用 malloc 时出错

    I pass char input from main to processInExp 函数 然后我再次传递它processInExp 功能为getInput 函数在读取文件时动态分配它 Inside getInput 功能input检查时