C Program to Convert the Content of File to Lowercase

This C Program converts the content of file to lowercase.

Here is source code of the C Program to convert the content of file to lowercase. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Convert the Content of File to LowerCase
  3.  */
  4. #include <stdio.h>
  5. #include <errno.h>
  6.  
  7. int to_lower_file(FILE *);
  8.  
  9. void main(int argc, char * argv[])
  10. {
  11.     int op = -1;
  12.     char ch;
  13.     FILE *fp;
  14.     if (fp = fopen(argv[1], "r+"))
  15.     {
  16.         printf("FILE has been opened..!!!\n");
  17.         op = to_lower_file(fp);
  18.         printf(" %d \n", op);
  19.         fclose(fp);
  20.     }
  21.     else
  22.     {
  23.         perror("Error Occured");
  24.         printf(" %d\n ", op);
  25.     }
  26. }
  27.  
  28. int to_lower_file(FILE *f)
  29. {
  30.     int c;
  31.     char ch;
  32.     while ((ch = fgetc(f))! = EOF)
  33.     {    
  34.         c = (int)ch;
  35.         if (c >= 65 && c <= 90)
  36.         {
  37.             ch = ch + 32;
  38.             fseek(f, -1L, 1);
  39.             fputc(ch, f);
  40.         }
  41.     }
  42.     return 0;
  43. }

$ 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.

Sanfoundry Global Education & Learning Series – 1000 C Programs.

advertisement
advertisement

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.