S
someone
I tried to make a program that's called "Don't Shout", that reads from
a file "input.dat", and all letters should be lower-case, expect for
the first letter, and any letter after a period should be capitalized.
It's just, after I finished, it seems that compilers produce all these
strange errors. I tried it on DJGPP, MVC++ and Borland C++, with no
luck. Help would be greatly appreciated! Here is the code:
/*dontshout.c*/
#include <stdio.h>
#include <stdlib.h>
#define PER 2
#define CAPS 1
#define LOW 0
int main(void)
{
FILE *fp;
if( (fp=fopen("input.dat","r"))==NULL)
{
fprintf(stderr,"Error Opening File!");
exit(-1);
}
else
{
int marker=CAPS;
while(1)
{
int ch;
ch =fgetc(fp);
if(!feof(fp))
{
/*Checking for shouting cases*/
if((marker==CAPS) && ((ch=>'A' && ch=<'Z')||(ch=>'a' && ch=<'z'))
{
prinf("%c",ch);
marker=LOW;
continue;
}
if(marker==PER && ch=>'a' && ch=<'z')
{
ch+=32;
marker=LOW;
continue;
}
if(ch=='.'|| ch=='?')
{
marker=PER;
continue;
}
if(marker==LOW && ch=>'A' && ch=<'Z')
{
ch+=32;
prinf("%c",ch);
continue;
}
printf("%c",ch);
}
else
{
break;
}
}
}
fclose(fp);
return 0;
}
Thanks
a file "input.dat", and all letters should be lower-case, expect for
the first letter, and any letter after a period should be capitalized.
It's just, after I finished, it seems that compilers produce all these
strange errors. I tried it on DJGPP, MVC++ and Borland C++, with no
luck. Help would be greatly appreciated! Here is the code:
/*dontshout.c*/
#include <stdio.h>
#include <stdlib.h>
#define PER 2
#define CAPS 1
#define LOW 0
int main(void)
{
FILE *fp;
if( (fp=fopen("input.dat","r"))==NULL)
{
fprintf(stderr,"Error Opening File!");
exit(-1);
}
else
{
int marker=CAPS;
while(1)
{
int ch;
ch =fgetc(fp);
if(!feof(fp))
{
/*Checking for shouting cases*/
if((marker==CAPS) && ((ch=>'A' && ch=<'Z')||(ch=>'a' && ch=<'z'))
{
prinf("%c",ch);
marker=LOW;
continue;
}
if(marker==PER && ch=>'a' && ch=<'z')
{
ch+=32;
marker=LOW;
continue;
}
if(ch=='.'|| ch=='?')
{
marker=PER;
continue;
}
if(marker==LOW && ch=>'A' && ch=<'Z')
{
ch+=32;
prinf("%c",ch);
continue;
}
printf("%c",ch);
}
else
{
break;
}
}
}
fclose(fp);
return 0;
}
Thanks