How to simply modify this code to enable reading text from file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to simply modify this code to enable reading text from file?

I was working on very simple code changing small letters for capitals and vice versa. I have this: #include <stdio.h> #include <ctype.h> #include <string.h> int main() { int znak; while ((znak = getchar())!=EOF) { if( islower(znak) ) { znak = toupper(znak); } else if( isupper(znak) ) { znak = tolower(znak); } putchar(znak); } return 0; } But whenever i try to rewrite this in way that would allow reading txt files I have stupid problem during using fgets&scanf. They are able to read only one line of txt file bc they always stop on '/n'. I've tried using loops and char buffors. It worked but all my methodes seemed to be overcomplicated and they took definitely too much memory. I'd like to see the simplest way to reach that.

31st Aug 2020, 4:53 PM
Daniel Brodowski
Daniel Brodowski - avatar
1 Answer
6th Sep 2020, 12:53 AM
Nils R
Nils R - avatar