Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
One of your colleagues did a huge mistake while storing the names of the employees into a file named "names.txt" that he was handling by storing all the names in lower case. But the requirement is to generate a report where all the names are in caps.

Write a c program to update the lower case characters in file to upper case


Let's consider

Names are stored in file like shown below

hari

jegan

sudhan

anil

yasika



Updated Names in File

HARI

JEGAN

SUDHAN

ANIL

YASIKA

What I have tried:

C
<pre>#include<stdio.h>
#include<string.h>


void main()
{
 
   FILE *fp;
   int i;
   char str[5][10],msg[10],n;
   
   fp=fopen("names.txt","r");
   //fp=fopen("names.txt","w");
  for(i=0;i<5;i++)
   {
       //fgets(str[i],4,fp);
       fscanf(fp,"%s",str[i]);
    //  strcpy(msg,strupr(str[i]));
    int fgetc(FILE *fp);
        // puts(msg);
   }
  
   fclose(fp);

}
Posted
Updated 27-Sep-17 8:06am
v2

1 solution

0) Create a char array inputString to hold the lines as you read them, and a char* pointer outputString to hold the pointer to the uppercased version.
1) Open the input file.
2) Open the output file.
3) Loop until the input is finished.
3.1) Inside the loop, read a line from the input.
3.2) Use strupr to convert the string to uppercase:
C++
outputString = strupr(inputString);

3.3) Write the the output to the output file.
4) After the loop, close both files.

But this is your homework, so that's all the code you will get!
 
Share this answer
 
Comments
Richard MacCutchan 27-Sep-17 15:58pm    
You should be charging for some of these answers.
OriginalGriff 27-Sep-17 16:12pm    
If I thought the cheque wouldn't bounce ... :sigh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900