I am opening a file for writing and changing it a bit. I have changed all uppercase characters to lowercase. I have also deleted all characters that are not alphabetic, but I can't delete apostrophes that occur after and before another alphabetic character (i.e. the word "there's" or "don't" would be a word with this condition). Here's my code thus far:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int fgetc(FILE *fp);
char *strcat(char *file1, const char *file2);
int isalpha(int c);
int main ()
{
char file1[1000];//Array for first file
char file2[1000];//Array for second file
int character;
char c;
//Ask for file to load and store it into a variable
printf ("Enter a filename to load: ");
scanf ("%s" , &file1);
//Opening file to write
FILE *fp;
fp = fopen(file1, "w");
printf ("\nFile successfully loaded!\n\n");
//Reading each character of the file until EOF
while ((character = fgetc(fp)) != EOF)//read each char from file until end of file
{
fscanf(fp, "%c ", c);
if (isalpha(c)) //if c equals a alphabetic character, make it lower case
{
c = tolower(c);
}
else //c is not an alphabetic character
{
if (c != 0x27)//if c is not equal to single quote
{
c = 0x20;//make it equal to white space
}
else //c is a single quote
{
//How do I make the single quote be counted if there is an
//alphabetic character to the left and to the right of it?
}
}
}
//Changes the name of the existing file to have .tmp appended to it
file2 = strcat(file1, ".tmp");
//Displays an error if file couldn't be found
else
{
printf ("Error, reading file!\n");
}
//Closes writeable file
fclose(fp);
//Opens file that is appended with ".tmp"
fp = fopen (file2, "r");
fclose(fp);
system("PAUSE");
return 0;
}
I have checked everywhere for it, but to no avail. I thought about doing something like, if c-1 and c+1 are alphanumeric then it's fine or return 1, else return 0, but I'm certain I'm doing something wrong there. Any help is appreciated