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

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

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

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?

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.

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

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?

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 5 Years Ago by Aia: grammar correction

ch=fgetc(cfptr);
while (ch!= EOF){
      printf ("%c", ch);
//-----------------^ put it right here
      ch=fgetc(cfptr);
This article has been dead for over six months. Start a new discussion instead.