0

i wrote a program to take text from a file of my choice named "data" and print it out on the screen, how can i tweak this so taht when the text comes out , it would be all in upper case using toupper??
this is the code

#include <stdio.h>
#include <ctype.h>

int main () {
    char ch;
    char abc;
    
FILE*cfptr=fopen("data.txt" , "r");

ch=fgetc(cfptr);
while (ch!= EOF){
      printf ("%c", ch);
      ch=fgetc(cfptr);
    
  
      }
      fclose (cfptr);

printf ("%c", ch);      
      scanf ("%c", abc); //keeps  output on screen
      
return (0);
}

thanks

5
Contributors
9
Replies
12
Views
6 Years
Discussion Span
Last Post by DarkPyros
0

you could use toupper() but also you could try an if statement:

if(ch is between 'a' and 'z')
     ch+=('A'-'a');
0

i wrote a program to take text from a file of my choice named "data" and print it out on the screen, how can i tweak this so taht when the text comes out , it would be all in upper case using toupper??

1) what does toupper() do?
2) how do you call it?
3) what does it return?
4) where is the most logical place to put the call to accomplish your task?

0

toupper() converts a character to its uppercase. you call it like this:

toupper(ch);

it returns the uppercase equivalent to ch.

check this if you want to learn more.

Votes + Comments
Doesn't deserve negative rep.
Thank you so much for making my post worthless.
0

i know what touppuer does, it takes a character that is in common and printf it capital...but how do i insert it into the program so it would print all of the letters capital?

0

i know what touppuer does, it takes a character that is in common and printf it capital...but how do i insert it into the program so it would print all of the letters capital?

If you know what toupper() does, place it in a loop to iterate the strings you want to translate.

Edited by Aia: grammar correction

0
ch=fgetc(cfptr);
while (ch!= EOF){
      printf ("%c", ch);
//-----------------^ put it right here
      ch=fgetc(cfptr);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.