CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2008
    Posts
    19

    problem with bool function in C

    Hello.
    I'm trying to build a program that will identify (from a text file given to it)
    a palindrome.
    Now i know that my program does not work and i need to work things around a bit but i keep receiving this strange error about bool function:

    Code:
    error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘isPalindrome’
    my program is this (it uses the reverse fnction that i have built to reverse the string and if there is white spaces in that string - it will ignore them to form one big string that i can work with later.)

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    
    bool isPalindrome(char fname[50]);
    char *str_dopel(char *str1);
    
    char *str_dopel(char *str1)
    {
       register int i;
       char *str2;
       str2 = malloc(sizeof(str1));
       int ascii_value;
       int length = strlen(str1);
       for (i = strlen(str1)-1; i > -1; i--) {
    
             ascii_value = (int)str1[i];
             if (ascii_value == 32) {
    
             }else
             {
               str2[length - i] = str1[i-1];
               }
    
               }
    
    
       return (str2);
    
      }
    
    
    bool isPalindrome(char fname[50])
    {
     FILE *file;
    
     file = fopen(fname, "r");
     if (file == NULL) {
     printf("Error: Cannot open file.\n");
     return false;
     }
     else {
     printf("File Opened, checking for palindrome...");
    }
    char line[BUFSIZ];
    char data[20][32];
    while (fgets(line, sizeof line, file) != NULL)
    {
       if (str_dopel(line) == line)
          printf("%s\n", line);
          return true;
       } else
       {
         printf("not palindrome\n");
    return false;
        }
    
    }
    int main(void)
    {
       char name[50];
       printf("Please enter the path to the file to be checked for palindromes: ");
       scanf("[^\n]", name);
       isPalindrome(name);
    
      return 0;
      }

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: problem with bool function in C

    Looks like you're compiling using the c compiler and your compiler doesn't support c99 ( bool is not supported earlier ). if so, use int instead.
    if your c compiler does supports c99 you should
    Code:
    #include <stdbool.h>
    You could also use the c++ compiler to compile your code.

    btw you have to
    Code:
    #include <stdlib.h>
    as well ( for malloc ).
    Kurt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured