Some structure and Syntax Help Please!
This is a palindrome assignment. The program needs to be divided into three files. 1 header, 2 .c files.
The main .c file is pal.c and it's purpose is only to read a file from the command line. using either ./pal < file.txt ...or ./pal files.txt
then it calls the function that is in checkpal.c
In checkpal.c ...the requirement is to use arrays and not pointers to store and manipulate the palindrome. In this file is also the printing of whether it is a palindrome or not. In addition to this, it is obvious that we have to exclude whitespace, as well as punctuation. Also, I must convert uppercase characters to lower case.
With that said. I've done this code. In three different files. But i'm unsure of my structure and syntax. Please bare in mind that i'm really new to this stuff. I have great difficulty in figuring out how to use all these functions and statments and arguments.
If it would be possible to explain the problems and errors in really simple terms, as this stuff doesn't come easy to me, it would be really apprieciated.
pal.c
Code:
#include <stdio.h>
#include "checkpal.h"
void read(FILE *fp);
int main(int argc, char *argv[])
{
int count;
FILE *fin;
if (argc == 1)
Checkifpal();
else {
for (count = 1; count < argc; count++) {
if (argc > 2)
printf("\n==> %s <==\n", argv[count]);
if ((fin = fopen(argv[count], "r")) == NULL)
fprintf(stderr, "Cannot Open File %s\n", argv[count]);
else {
read(fin);
}
}
}
return 0;
}
void read(FILE *fp)
{
int lines;
char buf[BUFSIZ];
for (lines=0; lines < MAX_LINES; lines++) {
if (fgets(buf, BUFSIZ, fp) == NULL)
return;
printf("%s", buf);
}
}