Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Where am I going wrong (file open,changecase,write)

Reply
Thread Tools

Where am I going wrong (file open,changecase,write)

 
 
barnetod@gmail.com
Guest
Posts: n/a
 
      01-09-2007
I am trying to open a text file designated by the user.

Then I want to change all lower case values to capital letters.

Then write file.

I am stuck and can not change the characters or am not writing
correctly.
Please let me know what I can do to fix this.

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

#define MAXCHAR 250
int main(void)
{
int c; /* for return value of fgetc */
FILE *fp;
char filename[MAXCHAR];

printf("Enter the name of the file to open\n");
fgets(filename, MAXCHAR, stdin);
filename[strlen(filename) - 1] = '\0';

if (!(fp = fopen(filename, "r")))
{
printf("Unable to open %s\n", filename);
exit(EXIT_FAILURE);
}

while((c = fgetc(fp)) != EOF)
{
if(islower((unsigned char)c))
{
c=toupper(c);
}
fclose(fp);
}


printf("The file has been converted to all Capital letters.\n\n\n");
system("Pause");
return 0;

}

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      01-10-2007
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:
> while((c = fgetc(fp)) != EOF)
> {
> if(islower((unsigned char)c))
> {
> c=toupper(c);
> }
> fclose(fp);
> }


Wouldn't it be best to write the characters out again? And wait until
after reading all the characters before closing the file?

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Windows XP: Going, going ... gone? OTHMAN MCSE 2 03-25-2008 04:45 PM
XP search going all lame on me..explorer going crazy when trying tosearch. fotoobscura Computer Support 8 01-12-2008 01:09 AM
Firefighters at the site of WTC7 "Move away the building is going to blow up, get back the building is going to blow up." Midex Python 24 05-07-2007 04:23 AM
floppy drive just keeps on going and going and ... Weylon Bulloch Computer Support 1 09-07-2003 07:17 AM
VPN going up but traffic going one way PLP Cisco 1 07-11-2003 08:28 AM



Advertisments