So, i'm having a bracket issue in line 83:9 or where the slashes are. it's telling me " error: expected identifier or '(' before '{' token", I don't understand how i am receiving this error. If somebody can explain to me how I'm receiving it, thank you.

   _Bool palindromes(char string[])
    {
    int i = 0;
    while(string[i]=0 != '\0')
            {
            i++;
            int last_place = i - 1;
                    for(int n=0; n<=last_place; n++)
                            {
                    if(string[n] == string[last_place])
                    {
                    last_place--;
                    continue;
                    }

                    if(n !=last_place)
                    {
                    return false;
                    }

                            }
            }

      }

    { //here is the issue
    while(string[i]=0 != '\0')
    int i=0;
            {
            i++;
            int last_place = i - 1;
                    for(int n=0; n<=last_place; n++)
                    {
                    if(string[n] == string[last_place])
                            {
                    return true;
                            }
                    }
            }
       }

Dani AI

Generated

Three independent problems explain the compiler error and the incorrect behavior seen in the thread: a stray/mismatched brace that opens a block where the compiler expects a declaration (this is what produces the message "error: expected identifier or '(' before '{' token"), a loop-condition that uses assignment/wrong grouping instead of a proper comparison to the NUL terminator, and variable-scope/redeclaration plus missing return paths. 's snippet shows these symptoms; 's advice to re-indent is exactly the right first step, and is correct to call out the unexpected brace after the function close.

Practical fixes, in order:

  • Remove the stray opening brace (or make that block a properly declared function). A bare { at file scope or immediately after a } that closed a function triggers the exact compiler error shown.
  • Fix the string-termination test so it compares to the NUL character rather than assigning or mis-grouping expressions. Use a clear condition like s[i] != '\0', or better, compute length once and use two indices.
  • Avoid redeclaring the same variable in overlapping scopes; declare loop counters where they belong.
  • Ensure every control path returns a boolean value.

A concise, reliable pattern is the two-index approach (left/right) — compute the last index, compare characters while left < right, decrement/increment the indices, and return true at the end. Example implementation:

#include <stdbool.h>
#include <string.h>

bool is_palindrome(const char *s)
{
    if (!s) return false;
    size_t left = 0;
    size_t right = strlen(s);
    if (right == 0) return true;
    right--;

    while (left < right) {
        if (s[left] != s[right]) return false;
        left++;
        right--;
    }
    return true;
}

Final notes: compile with -Wall -Wextra -pedantic -std=c11 to catch these mistakes early, use an editor or clang-format to reveal mismatched braces, and run simple tests (empty string, single char, even/odd length) to validate behavior.

Recommended Answers

All 2 Replies

Try re-indenting your code with a consistent formatting of your brace brackets. For example, in some cases your { is placed at (almost) the same level following a statement as in

_Bool palindromes(char string[])
 {

and then you do

if(string[n] == string[last_place])
        {
return true;
        }

You also do

while(string[i]=0 != '\0')
int i=0;
        {
        i++;

which makes no sense. If you apply a consistent style and make your indentation actually match your control structures your problem will become more obvious.

While it's poorly formatted (F rated), line 26 as presented doesn't make sense to me why there is a brace there. That is, you have your _Bool palindromes and it's left brace on line 2 and on line 24 it's closing right brace then you have an opening brace without a reason why. No new function or such so ... explain why you did that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.