So I ve got this:
char table1[10^length][length];
char table2[10^length][length];
And compiler doesn’t let me dot this:
table1=table2;
my code is supposed to take a string with wild caracters (only ?)
and give all the possible strings in the output (well it is a part of a bigger project but lets say print them in terminal – if I do this I can handle the rest)
Here is the full code:
int ** wildReplacement(char *wildAM,int length)
{
length=7;
char * temp;
strcpy(wildAM,"123?23");
//getchar();
int i=0;
int j=0;
int k=0;
int l=0;
int limit=0;
int wildCharsNum;
char *nlptr= NULL;
char table1[10^length][length];
char table2[10^length][length];
wildCharsNum=charOccurenciesInStr(wildAM,'?');
strcpy(temp,wildAM);
strcpy(table1[0],wildAM);
printf("\n!!WildChars In wildAM:%d",wildCharsNum);
while(k<wildCharsNum)
{
l=0;
while(l<=limit)
{
strcpy(temp,table1[l]);
i=0;
nlptr = strchr(temp, '?');//ka8e fora vriskei to epomeno ?
if (nlptr)
{
for(j=1;j<10;j++)
{
*nlptr = myItoc(j);//antikatastasi tou ? me digits sto temp
strcpy(table2[i],temp);
i++;
}
}
l++;
}
table1=table2;
limit=i;
k++;
}
printf("\nWild Numbers out:");
for(i=0;i<limit;i++)
{
printf("\n%s",table1[i]);
}
}
Should I malloc like:
char ** table1
char ** table2
table1=malloc(sizeof(char)*10^length*lenght)
table2=malloc(sizeof(char)*10^length*lenght)
How would the programm know when each record ends
Then what would this mean:
table1[1] ? probably nothing…
Thanks in advance
When you
malloca two dimensional array you can’t construct something that’s identical to what the compiler would make for an array declaration.char a[100][50]is a contiguous blob of memory that’s 5000char. When you subscript it the compiler is able to do the row/column math because it knew the size at compile time. When youmallocan equivalent two-dimensional array you have to provide a row array that indexes the rows. This is how you answer your question “how would the program know when each record ends”:Notice that this takes more memory than the declared array because of the
rowsindexing array.As an optimization you can avoid the repeated
mallocin the loop and parcel out memory from a single large allocation ofrows * cols * sizeof(**b).Take care you write a matching function to
freeyour array.