Code:
#include stdio.h
#include errno.h
int to_lower_file(FILE *);
void main(int argc, char * argv[])
{
int op = -1;
char ch;
FILE *fp;
if (fp = fopen(argv[1], "r+"))
{
printf("FILE has been opened..!!!\n");
op = to_lower_file(fp);
printf(" %d \n", op);
fclose(fp);
}
else
{
perror("Error Occured");
printf(" %d\n ", op);
}
}
int to_lower_file(FILE *f)
{
int c;
char ch;
while ((ch = fgetc(f))! = EOF)
{
c = (int)ch;
if (c >= 65 && c <= 90)
{
ch = ch + 32;
fseek(f, -1L, 1);
fputc(ch, f);
}
}
return 0;
}
Output:
$ gcc file4.c
$ cat test1
THE FUNCTION STRERROR RETURNS A POINTER TO AN ERROR MSG STRING WHOSE CONTENTS ARE IMPLEMENTATION DEFINED.
THE STRING IS NOT MODIFIABLE AND MAYBE OVERWRITTEN BY A SUBSEQUENT CALL TO THE STRERROR FUNCTION.
$ ./a.out test1
FILE has been opened..!!!
0
$ cat test1
the function strerror returns a pointer to an error msg string whose contents are implementation defined.
the string is not modifiable and maybe overwritten by a subsequent call to the strerror function.
More C Programs: