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

Recommended Answers

All 9 Replies

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.

commented: Thank you so much for making my post worthless. -4
commented: Doesn't deserve negative rep. +14

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.

ch=fgetc(cfptr);
while (ch!= EOF){
      printf ("%c", ch);
//-----------------^ put it right here
      ch=fgetc(cfptr);

http://java2s.com/
i think youve gotta visit this site...hope it will help...
just try..theres no harm in trying...:-)

thanks all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.