如果满足条件,可以在每次迭代时放大数组吗?

JAN*_*JAN 0 c malloc

我有这个结构

typedef struct
{
    int numberPipes;              // |
    int numberAmpersands;         // &
    int existsBiggerThan;         // >
    int existsLessThan;           // <
    int existsDoubleLargerThan;   // >>

} lineData;
Run Code Online (Sandbox Code Playgroud)

和我在一个循环中运行char阵列(字符*),以找到所有索引'&''|'.

我不知道有多少'&''|'我要去寻找.是否可以从两个malloc大小为1的数组(使用)开始,并在每次迭代后放大它们,只有当我发现其中一个的另一个出现时?

MBy*_*ByD 5

你可以通过电话来做到这一点realloc.

出于性能原因,最好不要为每个新元素调用它,而是在X元素中调用它,这样可以减少对malloc/ 的调用次数realloc.