'issue in changing contents of file from lower case to upper case
I am trying to change the contents in a file from lower to upper case by using the code below. It got stuck in an infinite loop. What is the mistake here?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *fp = fopen("file.txt", "r+");
if (fp == NULL)
{
printf("error occured");
exit(1);
}
char c;
while ((c = fgetc(fp)) != EOF)
{
if (islower(c))
{
fseek(fp, -1, SEEK_CUR);
fputc(toupper(c), fp);
}
//fseek(fp, 0, SEEK_CUR);
}
fclose(fp);
return 0;
}
The programme is working fine if the commented line is uncommented.
If possible, please mention some good resource for knowing about fseek function in detail.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
