Refresher questions in C/C++

N

Niall 84

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

dj3vande

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
 
D

Default User

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
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top