I can´t read from the char array
This is how I pass the string into my array for each test case and that works fine but passing the array is a problem. I looked it up here:
Passing arrays and matrices to functions as pointers and pointers to pointers in C
I still get the warning that I compare between a pointer and an integer.
char klammern[MAX][STRING];
int i, test;
int ergebnis;
printf(" Test cases?:");
scanf("%d",&test);
getchar(); //catch Enter
for(i=0;i<test;i++)
{
fgets(klammern[i],30,stdin);
}
Here is how I pass the argument:
for(i=0;i<test;i++)
{
ergebnis = matching_brackets( klammern );
printf("%d ",ergebnis);
}
My function should count the numbers of brackets and return 1 if not all brackets are closed and 0 if everything is correct.
int matching_brackets(char (*klammern)[STRING])
{
int ergebnis, i;
int runde_klammern = 0;
for(i=0; *klammern[i] != '\n';i++)
{
if( *klammern[i] == '(')
{
runde_klammern++;
}
else if( *klammern[i] == ')')
{
runde_klammern--;
}
ergebnis = runde_klammern;
if ( ergebnis != 0)
{
return 1;
}
else
{
return 0 ;
}
While testing I saw that my for loop in the function read my array like this:
array [1][0]
array [2][0]
...
I want to loop the array like:
array[0][0]
array[0][1]
...
Edit: I do not get the compiler warning anymore after I fixed a typo in my function.