im wanting to read in from 1 text file, and write to another, i want to take an ALL CAPS file
ex) THIS IS MY FILE IT IS A BUNCH OF CRAP. BLAH
BLAH BLAH, BLAH BLAH, BLAH BLAH!!!
and write it to another so that it looks like this
ex)This is my file it is a bunch of crap Blah
blah blah, blah blah, blah blah!!!
i wrote it, and im getting some wierd errors, im wanting to stick with stdio.h. but like i said, im getting some wierd errors...can you guys check out my code??
THANKS!
****************
Code:
#include <stdio.h>
int UPPERtoLOWER(int ch);
void SearchString(char *sentence);
int i = 0;
int main()
{
char sentence[500];
FILE *rptPTR; /* file pointer to the report*/
FILE *updatePTR; /* file pointer to the updated file*/
if (( rptPTR = fopen("report.txt", "r") ) == NULL )
{
printf("File could not be opened!\n");
}
if (( updatePTR = fopen("update.txt", "w") ) == NULL )
{
printf("File could not be opened!\n");
}
else
{
while(fgets(sentence, 500, rptPTR) != NULL)
{
printf("%s", sentence);
}
printf("\n");
if (( updatePTR = fopen("update.txt", "w") ) == NULL )
{
printf("File could not be opened!\n");
}
else
{
SearchString(sentence);
fwrite(sentence, sizeof(char), sizeof(sentence), updatePTR);
}
fclose(rptPTR);
fclose(updatePTR);
printf("Your file has been updated!\nLook for update.txt\n");
}
return 0;
}
int UPPERtoLOWER(int ch)
{
if (( 'A' <= ch) && (ch <= 'Z' ))
{
return (ch - 'A' + 'a');
}
else
{
return ch;
}
}
void SearchString(char *sentence)
{
char space = ' ';
char period = '.';
char exclam = '!';
char questmk = '?';
static int C=1;
for (i = 0; sentence[i] != '\0'; i++)
{
if ((sentence[i] == period) || (sentence[i] == exclam) || (sentence[i] == questmk))
{
C=1;
}
if( C && 'A' <= sentence[i] && sentence[i] <= 'Z' ){
C=0;
}else{
sentence[i] =(char)UPPERtoLOWER(sentence[i]);
}
}
}