Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C programming problem

205 views
Skip to first unread message

Eric Walz

unread,
May 16, 2013, 4:50:22 PM5/16/13
to
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

James Kuyper

unread,
May 16, 2013, 5:40:24 PM5/16/13
to
What does your current code look like?

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

Edward A. Falk

unread,
May 16, 2013, 6:38:22 PM5/16/13
to
In article <51955248...@verizon.net>,
James Kuyper <james...@verizon.net> wrote:
>On 05/16/2013 04:50 PM, Eric Walz wrote:
>>
>> I am new to learning C and could use some help. Thank you.
>
>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.

--
-Ed Falk, fa...@despams.r.us.com
http://thespamdiaries.blogspot.com/

BruceS

unread,
May 16, 2013, 6:38:41 PM5/16/13
to
Not the macro?

Keith Thompson

unread,
May 16, 2013, 7:26:46 PM5/16/13
to
BruceS <bruc...@hotmail.com> writes:
> 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.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Mark Bluemel

unread,
May 17, 2013, 3:19:54 AM5/17/13
to
On 16/05/2013 23:38, Edward A. Falk wrote:
> In article <51955248...@verizon.net>,
> James Kuyper <james...@verizon.net> wrote:
>> On 05/16/2013 04:50 PM, Eric Walz wrote:
>>>
>>> I am new to learning C and could use some help. Thank you.
>>
>> 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.
>
:-)

Heinrich Wolf

unread,
May 17, 2013, 3:44:01 AM5/17/13
to

"James Kuyper" <james...@verizon.net> schrieb im Newsbeitrag
news:51955248...@verizon.net...
...
> The key insight is that you'll need to use the toupper() function.

or the strupr() function

Heiner

Malcolm McLean

unread,
May 17, 2013, 4:31:20 AM5/17/13
to
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).

James Kuyper

unread,
May 17, 2013, 8:07:36 AM5/17/13
to
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.
--
James Kuyper

Jorgen Grahn

unread,
May 17, 2013, 8:43:57 PM5/17/13
to
On Fri, 2013-05-17, Malcolm McLean wrote:
> On Thursday, May 16, 2013 9:50:22 PM UTC+1, Eric Walz wrote:
>>
>>
>> Can anyone give me some insights on this programming problem for a project?

An exercise, surely.

>> 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 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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Heinrich Wolf

unread,
May 18, 2013, 5:36:38 AM5/18/13
to
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

Malcolm McLean

unread,
May 18, 2013, 7:45:32 AM5/18/13
to
On Saturday, May 18, 2013 1:43:57 AM UTC+1, Jorgen Grahn wrote:
> 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.

Rob

unread,
May 22, 2013, 7:48:42 AM5/22/13
to
On Sat, 18 May 2013 11:36:38 +0200, Heinrich Wolf wrote:

> 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.

Heinrich Wolf

unread,
May 22, 2013, 12:30:19 PM5/22/13
to

"Rob" <nite...@gmail.com> schrieb im Newsbeitrag
news:knibaq$nkf$1...@dont-email.me...
...
> 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

BruceS

unread,
May 22, 2013, 5:11:19 PM5/22/13
to
On 05/16/2013 05:26 PM, Keith Thompson wrote:
> BruceS <bruc...@hotmail.com> writes:
>> 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.
0 new messages