Refresher questions in C/C++

Discussion in 'C Programming' started by Niall 84, Oct 29, 2008.

  1. Niall 84

    Niall 84 Guest

    Hi all,

    Haven't done C or C++ in a few years and have never done a huge amount
    of it.

    I'm trying to do some very basic programmes at the moment to get back
    into it.
    1st of all I'm using Microsoft Visual C++ (2005 I think). Can this be
    used as a C compiler or is it just C++?
    I am also trying to use the scanf to take back in a value but it seems
    to be giving me problems. its giving a warning about using it and also
    when I do execute it (Using a different programme to MSVC) as soon as
    I put in an input the window closes instead of displaying what it
    should display after my scanf. These are probably very stupid problems
    but as I said I forget most of what i've learnt about C!!!!

    Thanks,

    Niall.
     
    Niall 84, Oct 29, 2008
    #1
    1. Advertising

  2. Niall 84

    Guest

    In article <>,
    Niall 84 <> wrote:
    >Hi all,
    >
    >Haven't done C or C++ in a few years and have never done a huge amount
    >of it.
    >
    >I'm trying to do some very basic programmes at the moment to get back
    >into it.


    Not really related to your questions, but you should check out
    <http://www.c-faq.com/>.
    Carefully reading through the whole thing won't be time wasted; if
    you're in a hurry, at least look through the table of contents so you
    know what's there for when you run into questions that it answers.


    >1st of all I'm using Microsoft Visual C++ (2005 I think). Can this be
    >used as a C compiler or is it just C++?


    Very probably. Most compilers that support both languages make their
    decision based on the filename. The people in
    comp.os.ms-windows.programmer.win32 or in a MSVC-specific newsgroup
    will be able to give you details if you can't figure it out yourself.

    >I am also trying to use the scanf to take back in a value but it seems
    >to be giving me problems. its giving a warning about using it


    Depending on what that warning is, it may or may not be safe to ignore
    it.
    If it's complaining about using a function that hasn't been declared,
    or about the arguments not matching what they're supposed to be, it
    probably means there's an error in your code.
    If it's complaining that scanf itself is somehow bad, then you should
    try to find a way to turn that warning off. (Especially if you can do
    it without turning off similar warnings for gets, which *is* inherently
    bad.)

    For nontrivial user input, scanf is usually not what you actually want
    to use anyways. The C FAQ has details on the problems with scanf and
    on alternate ways of getting input.

    > and also
    >when I do execute it (Using a different programme to MSVC) as soon as
    >I put in an input the window closes instead of displaying what it
    >should display after my scanf.


    Solution #1 (portable, but suboptimal): At the end of main(), when
    your program has finished what it's actually meant to do, print a
    "Press Enter to continue" prompt and wait for (then discard) user input
    before you terminate. (This may turn up one of the aforementioned
    problems with scanf.)

    Solution #2 (probably better): Configure your IDE to leave the
    program's window open until you close it. comp.lang.c is not the place
    to find out how to do this.


    dave

    --
    Dave Vandervies dj3vande at eskimo dot com
    But I don't daydream about being a [paramedic], because my subconscious knows
    that learning to fly unassisted is more likely than my being capable of being
    a paramedic. --David Cameron Staples in the scary devil monastery
     
    , Oct 29, 2008
    #2
    1. Advertising

  3. Niall 84

    Niall 84 Guest

    Thank you very much,
    I'll check out that C-Faq now.

    Niall
     
    Niall 84, Oct 29, 2008
    #3
  4. Niall 84

    Default User Guest

    Niall 84 wrote:


    > 1st of all I'm using Microsoft Visual C++ (2005 I think). Can this be
    > used as a C compiler or is it just C++?


    Generally, the MSVC suites contain both a C and C++ compiler. If the
    file ends in .c, it will compile as C.

    > I am also trying to use the scanf to take back in a value but it seems
    > to be giving me problems. its giving a warning about using it and also
    > when I do execute it (Using a different programme to MSVC) as soon as
    > I put in an input the window closes instead of displaying what it
    > should display after my scanf. These are probably very stupid problems
    > but as I said I forget most of what i've learnt about C!!!!


    Usually, adding a call to getchar() before the end will be sufficient
    for small programs. I assume you're running it by double-clicking. You
    can also open a command window and run it that way.




    Brian
     
    Default User, Oct 29, 2008
    #4
    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. richard
    Replies:
    6
    Views:
    343
    Jonathan N. Little
    Sep 18, 2006
  2. Ali Syed
    Replies:
    3
    Views:
    562
    Mark McIntyre
    Oct 13, 2004
  3. capes
    Replies:
    0
    Views:
    383
    capes
    Sep 9, 2005
  4. Good refresher site

    , Mar 12, 2007, in forum: C Programming
    Replies:
    11
    Views:
    532
    Keith Thompson
    Mar 13, 2007
  5. getline - refresher

    , Apr 9, 2009, in forum: C++
    Replies:
    2
    Views:
    270
    Jerry Coffin
    Apr 9, 2009
Loading...

Share This Page