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:
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:error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘isPalindrome’
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; }




Reply With Quote