Counting braces within a txt file
This is my first experience in programming...so I'm still learning. Please forgive any syntax or language errors. I am trying to write a program that reads from a .txt and verify the proper pairing of braces. For each left brace encountered there must be a right brace to close the statement. If rightCount ever exceeds leftCount, inserts the characters "??" at that point in the output. Here is what I have. Please any suggestions would be useful. It may not be a kosher program...but then again, that's why I'm here.
Code:
Code:
#include<stdio.h>
int main(void)
{
FILE *fpFileInput;
char ch;
int count = 0;
int getc (FILE *fpFileInput);
int leftCount = 0;
int rightCount = 0;
/* Verify File Access */
if ((fpFileInput = fopen("text.txt", "r")) == NULL)
{
printf ("\ERROR opening input file.\n");
}
while (ch != EOF)
{
ch = getc (fpFileInput);
if (ch == '{') leftCount++;
if (ch == '}') rightCount++;
/* Test BracesCount */
if (rightCount > leftCount) printf ("??");
elseif (leftCount > rightCount) printf ("??");
printf ("%c", ch);
} /* End While */
/* Close the Inupt File */
fclose (fpFileInput);
/* Test and Print Results */
/* NOT DONE HERE*/
if (leftCount > rightCount)
printf ("ERROR: Missing %d right braces.\n",rightCount );
elseif (rightCount > leftCount)
printf ("ERROR: Missing %d left braces.\n",leftCount );
}