每次运行函数时都要进行Malloc’ing并重置数组

struct variables { unsigned int counter; char *bra; unsigned int maxb; int *findtheking; unsigned int numoright; }; int getlen = 0; // I give getlen a value in another function int solo = 0; mat.bra = (char*)malloc(sizeof(char)*getlen); mat.bra = '\0'; struct variables pal = { 0, '\0', 0, 0, 0 }; struct variables mat = { 0, '\0', 0 , 0, 0 }; struct variables all = { 0, '\0', 0, 0, 0 }; struct variables alle = { 0, '\0', 0 , 0, 0}; 

Visual Studio告诉我

 mat.bra = (char*)malloc(sizeof(char)*getlen); *mat.bra = '\0'; 

两者都需要’;’ 而且我不明白为什么。 请帮忙?

如果我,我可以将malloc用于mat.bra吗?

 int matches(char* str, int len) { getlen = strlen(str); if (mat.counter >= strlen(str)) { if (mat.bra[strlen(str)-1] == '(') { mat.counter = 0; mat.bra[0] = '\0'; return 0; } else if (mat.bra[strlen(str)-1] == '0') { mat.counter = 0; mat.bra[0] = '\0'; return 1; } } else { if (str[mat.counter] == '(') { mat.bra[len-1] = str[mat.counter]; mat.counter++; matches(str, len - 1); } else if (str[mat.counter] == ')') { if (mat.bra[len] == '(') { mat.counter++; mat.bra[len] = '0'; matches(str, len + 1); } else { mat.counter = 0; mat.bra[0] = '\0'; return 0; } } else { mat.counter++; matches(str, len); } } } 

在第一块代码下有这个function吗?

我将在main.c中运行匹配,这些代码在func.c中

我试图在main.c中运行此函数匹配几次,并且我需要mat.bra每次运行时都有不同大小的strlen(str)。 以这种方式我甚至可以使用malloc吗?

对不起,如果我的问题含糊不清,我是编码的新手。 如果有什么需要改进,告诉我,我会尝试详细说明!