C programming problem

Discussion in 'C Programming' started by Eric Walz, May 16, 2013.

  1. Eric Walz

    Eric Walz Guest

    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
    Eric Walz, May 16, 2013
    #1
    1. Advertising

  2. Eric Walz

    James Kuyper Guest

    On 05/16/2013 04:50 PM, Eric Walz wrote:
    > 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.
    James Kuyper, May 16, 2013
    #2
    1. Advertising

  3. In article <>,
    James Kuyper <> 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,
    http://thespamdiaries.blogspot.com/
    Edward A. Falk, May 16, 2013
    #3
  4. Eric Walz

    BruceS Guest

    On 05/16/2013 03:40 PM, James Kuyper wrote:
    > On 05/16/2013 04:50 PM, Eric Walz wrote:
    >> 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.


    Not the macro?
    BruceS, May 16, 2013
    #4
  5. BruceS <> 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) <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"
    Keith Thompson, May 17, 2013
    #5
  6. Eric Walz

    Mark Bluemel Guest

    On 16/05/2013 23:38, Edward A. Falk wrote:
    > In article <>,
    > James Kuyper <> 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.
    >

    :)
    Mark Bluemel, May 17, 2013
    #6
  7. "James Kuyper" <> schrieb im Newsbeitrag
    news:...
    ....
    > The key insight is that you'll need to use the toupper() function.


    or the strupr() function

    Heiner
    Heinrich Wolf, May 17, 2013
    #7
  8. 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?
    >
    >
    >
    > 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).
    Malcolm McLean, May 17, 2013
    #8
  9. Eric Walz

    James Kuyper Guest

    On 05/17/2013 03:44 AM, Heinrich Wolf wrote:
    >
    > "James Kuyper" <> schrieb im Newsbeitrag
    > news:...
    > ...
    >> The key insight is that you'll need to use the toupper() function.

    >
    > 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.
    --
    James Kuyper
    James Kuyper, May 17, 2013
    #9
  10. Eric Walz

    Jorgen Grahn Guest

    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 .
    Jorgen Grahn, May 18, 2013
    #10
  11. 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
    Heinrich Wolf, May 18, 2013
    #11
  12. 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.
    Malcolm McLean, May 18, 2013
    #12
  13. Eric Walz

    Rob Guest

    Re: C programming problem [Off-topic: gconio.h]

    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.
    Rob, May 22, 2013
    #13
  14. Re: C programming problem [Off-topic: gconio.h]

    "Rob" <> schrieb im Newsbeitrag
    news:knibaq$nkf$...
    ....
    > 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
    Heinrich Wolf, May 22, 2013
    #14
  15. Eric Walz

    BruceS Guest

    On 05/16/2013 05:26 PM, Keith Thompson wrote:
    > BruceS <> 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.
    BruceS, May 22, 2013
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf

    Programming problem

    Ralf, Feb 24, 2005, in forum: VHDL
    Replies:
    2
    Views:
    459
    Jerry Coffin
    Feb 24, 2005
  2. hezhang
    Replies:
    5
    Views:
    666
    hezhang
    Feb 16, 2006
  3. Matt
    Replies:
    35
    Views:
    10,607
    George Neuner
    Jul 22, 2004
  4. Casey Hawthorne
    Replies:
    4
    Views:
    998
    Jarek Zgoda
    Aug 4, 2006
  5. Joe Mayo
    Replies:
    168
    Views:
    3,294
    David Thompson
    Oct 22, 2007
Loading...

Share This Page