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.
/*
* C Program to Convert the Content of File to LowerCase
*/
#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;
}
$ 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.
Related Posts:
- Check Computer Science Books
- Apply for Computer Science Internship
- Practice BCA MCQs
- Practice Computer Science MCQs
- Apply for C Internship