C programming problem

E

Eric Walz

Hello all,

Can anyone give me some insights on this programming problem for a project?

Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

I am new to learning C and could use some help. Thank you.

Eric
 
J

James Kuyper

Hello all,

Can anyone give me some insights on this programming problem for a project?

Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

I am new to learning C and could use some help. Thank you.

What does your current code look like?

The key insight is that you'll need to use the toupper() function.
 
E

Edward A. Falk

What does your current code look like?
+1

The key insight is that you'll need to use the toupper() function.

Huh. I thought the key insight was hexapodia. Shows what I know.
 
K

Keith Thompson

BruceS said:
On 05/16/2013 03:40 PM, James Kuyper wrote: [...]
The key insight is that you'll need to use the toupper() function.

Not the macro?

What macro?

Like any function in the standard library, toupper() may additionally be
implemented as a macro, but the standard describes it as a function.

The implementation I'm using (gcc and glibc) just provides the function,
not a macro.
 
M

Malcolm McLean

Can anyone give me some insights on this programming problem for a project?



Have a program prompt the user for a filename to open. Change every
alphabetic character in the file to a capital letter. Numbers and special
characters should not be changed. Print the output to the screen.

I am new to learning C and could use some help. Thank you.
Break the problem down.

First create a test file with some data in it. Remember to save as
a pure ACSII plain text file.
Then see if you can fopen() and fclose() it.
Then read the first character, echo it to the screen, and check it is right.
Then write a loop so you are echoing the whole file to the screen.
Then get the processing working.
Then replace your hardcoded filename with one obtained from the
user. (This is actually the hardest step to do robustly, but easy
if you limit the path to say 1024 characters).
 
J

James Kuyper

...

or the strupr() function

I did a quick search, and found many references to strupr(), but only
one that associates it with any particular standard:
<http://www.programiz.com/c-programming/library-function/strupr>
That site appears to claim that it's a C standard library function, but
that's not the case. I found a page identifying it as an obsolete
Microsoft implementation of a POSIX function, but I couldn't find
anything about it in the current POSIX standard.

If use of that function is acceptable as a solution to this problem,
then it would be more appropriate to discuss this problem in a forum
associated with the library that it is a part of, whichever library that is.
 
J

Jorgen Grahn

An exercise, surely.
Break the problem down.

First create a test file with some data in it. Remember to save as
a pure ASCII plain text file.

And remember that you have now narrowed down the instructor's rather
vague instructions to ASCII text files.
Then see if you can fopen() and fclose() it.

Or skip that part for now and read from stdin, write to stdout.

I don't quite understand why exercises like these always want you to
"prompt the user". In real non-GUI programs you try to avoid that
since it prevents automation, doesn't allow for filename completion
etc.
Then read the first character, echo it to the screen, and check it is right.
Then write a loop so you are echoing the whole file to the screen.
Then get the processing working.
Then replace your hardcoded filename with one obtained from the
user. (This is actually the hardest step to do robustly, but easy
if you limit the path to say 1024 characters).

Yes.

/Jorgen
 
H

Heinrich Wolf

ok.

I know strupr() from my good old Turbo C 2.0 . My Borland C++ Builder 5 also
has it and for portability it lists Win32 supported; UNIX, ANSI C, ANSI C++
not supported. My linux gcc has no strupr().

I am sorry having contributed it.

Heiner
 
M

Malcolm McLean

On Fri, 2013-05-17, Malcolm McLean wrote:


Or skip that part for now and read from stdin, write to stdout.

I don't quite understand why exercises like these always want you to
"prompt the user". In real non-GUI programs you try to avoid that
since it prevents automation, doesn't allow for filename completion
etc.
A real Unix program would read from stdin and write to stdout by
default, so it could be used as a filter in a Unixy pipe system. It
would also have an option to pass a filename on the commandline.

It is possible to drive programs through stdin from a master under
Unix, but it is a real grief. You have to create what is called a
pseudo-terminal to fool the system into thinking it is talking to
a human and prevent it buffering the input.
 
R

Rob

My linux gcc has no strupr().

I am sorry having contributed it.

Heiner

You may be interested in gconio.h. This includes strupr() and strlwr()
among other things, such as gotoxy().

It's a standalone header file implemented using ANSI escape sequences. It
works fine on my Linux GCC (Kubuntu 12.04 AMD64).

The homepage is here:

http://www.wence.vandermeersch.org/gconio/

Regards,

Rob.
 
H

Heinrich Wolf

....
You may be interested in gconio.h. This includes strupr() and strlwr()
among other things, such as gotoxy().

It's a standalone header file implemented using ANSI escape sequences. It
works fine on my Linux GCC (Kubuntu 12.04 AMD64).

The homepage is here:

http://www.wence.vandermeersch.org/gconio/

Regards,

Rob.

Thank you very much. I don't miss strupr() on my Linux. It is easy to
implement using toupper().
And if I need gotoxy(), I take curses.h

Heiner
 
B

BruceS

BruceS said:
On 05/16/2013 03:40 PM, James Kuyper wrote: [...]
The key insight is that you'll need to use the toupper() function.

Not the macro?

What macro?

Like any function in the standard library, toupper() may additionally be
implemented as a macro, but the standard describes it as a function.

The implementation I'm using (gcc and glibc) just provides the function,
not a macro.

That's interesting, and I've once again learned something. I had
believed the macro to be defined by the standard. Thank you for the
correction. I looked through my copy (always a skeptic), and of course
you are right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top