From: Ian Collins on
On 05/ 9/10 09:49 AM, Mike Barnard wrote:
> On Sun, 09 May 2010 09:35:52 +1200, Ian Collins<ian-news(a)hotmail.com>
> wrote:
>
>>> So my questions are:
>>>
>>> 1. What EACTLY is returned in scanf()? Is it an ascii code to start
>>> with so no conversion of any sort needed? Google returns lots of very
>>> detailed tech references which I don't yet understand but so far no
>>> plain English explanations. I'll keep looking though.
>>
>> That depends on the parameters you pass, which you haven't shown us.
>
> scanf ( "%d", Vnumberofns ) ;

In that case, you have a problem.

"%d" is telling scanf to read an integer value. To do that, the next
parameter must be the *address* of an int.

scanf( "%d", &numberofns );

So to revise my earlier comment:

If you are reading a single integer into an int, there's no need to mess
with ASCII values, just compare with 0 and 9.

>>> 2. Below is an INCOMPLETE function, but can you telL me why I'm
>>> getting the compiler error "syntax error before '{' token" on the line
>>> marked<<< please? Whats wrong with my declaration?
>>>
>>> //Declaration
>>> int Fcheckinput ( int Vnumberofns ); // Validates input
>
>> Get rid of the spurious leading capitals, they only serve to confuse the
>> reader.
>
> I'm using them to show me where I'm looking at a Function or Variable.
> I'm sure I'll develop a personal style in the long term.

Get used to using names that tell you whether you are looking at a
function or variable. Use nouns for variables and verbs for functions,
which you have done.

Two common naming conventions are using underscores : check_input and
mixed case: checkInput.

--
Ian Collins
From: Ben Cottrell on
Mike Barnard wrote:
> On Sat, 08 May 2010 22:46:35 +0100, Paul Bibbings
> <paul.bibbings(a)gmail.com> wrote:
>
>
>>Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:
>>
>><snip>
>>
>>>2. Below is an INCOMPLETE function, but can you telL me why I'm
>>>getting the compiler error "syntax error before '{' token" on the line
>>>marked <<< please? Whats wrong with my declaration?
>>>
>>>//Declaration
>>>int Fcheckinput ( int Vnumberofns ); // Validates input
>>>
>>>Main(){
>>>blah blah...
>>>}
>>
>> HERE
>> |
>> V
>>
>>>int Fcheckinput ( int Vnumberofns ); // Validates input
>>> { <<<
>
>
> What, the space between the t and the V? :) See my other reply, and
> thanks!

Paul was referring to the semicolon at the end of the line. a
semicolon denotes 'end of statement' - although here you look as if
you're trying to define a function (You have the body of the function
beginning on the next line).

a function signature with a semicolon afterwards is a declaration - i.e.
the compiler sees a statement which declares the existance of a
function, but is expecting the actual definition elsewhere.
From: Mike Barnard on
On Sun, 09 May 2010 08:34:28 GMT, Robert Billing
<unclebob(a)tnglwood.demon.co.uk> wrote:

>We, the Senate of Arcturus, take note that Mike Barnard said:
>
>> What, the space between the t and the V? :) See my other reply, and
>> thanks!
>
>Look at it in a fixed width font.

SEE the smiley? Yes, I got the stray semicolon, thank you.
From: Mike Barnard on
On Sun, 09 May 2010 07:27:31 +0100, Ben Cottrell
<email(a)address.invalid> wrote:

>Mike Barnard wrote:
>> On Sat, 08 May 2010 22:46:35 +0100, Paul Bibbings
>> <paul.bibbings(a)gmail.com> wrote:
>>
>>
>>>Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:
>>>
>>><snip>
>>>
>>>>2. Below is an INCOMPLETE function, but can you telL me why I'm
>>>>getting the compiler error "syntax error before '{' token" on the line
>>>>marked <<< please? Whats wrong with my declaration?
>>>>
>>>>//Declaration
>>>>int Fcheckinput ( int Vnumberofns ); // Validates input
>>>>
>>>>Main(){
>>>>blah blah...
>>>>}
>>>
>>> HERE
>>> |
>>> V
>>>
>>>>int Fcheckinput ( int Vnumberofns ); // Validates input
>>>> { <<<
>>
>>
>> What, the space between the t and the V? :) See my other reply, and
>> thanks!
>
>Paul was referring to the semicolon at the end of the line. a

I know, but it seems there's not too much humor inhere. Oh well, I'll
try to be all serious.

>semicolon denotes 'end of statement' - although here you look as if
>you're trying to define a function (You have the body of the function
>beginning on the next line).

Thats right, it was a function body.

>a function signature with a semicolon afterwards is a declaration - i.e.
>the compiler sees a statement which declares the existance of a
>function, but is expecting the actual definition elsewhere.

THIS is the sort of basic information I need, in plain English. Thank
you. A cryptic "here" hoping I'm using the same font wasn't that
helpful because as mentioned elsewhere I've only been looking at C for
a few hours and I know a fraction of a percent of F all so far.

I'd love to do a college course or something, but there isn't one in
my local college.
From: Mike Barnard on
On Sun, 09 May 2010 10:09:43 +1200, Ian Collins <ian-news(a)hotmail.com>
wrote:

>On 05/ 9/10 09:49 AM, Mike Barnard wrote:
>> On Sun, 09 May 2010 09:35:52 +1200, Ian Collins<ian-news(a)hotmail.com>
>> wrote:
>>
>>>> So my questions are:
>>>>
>>>> 1. What EACTLY is returned in scanf()? Is it an ascii code to start
>>>> with so no conversion of any sort needed? Google returns lots of very
>>>> detailed tech references which I don't yet understand but so far no
>>>> plain English explanations. I'll keep looking though.
>>>
>>> That depends on the parameters you pass, which you haven't shown us.
>>
>> scanf ( "%d", Vnumberofns ) ;
>
>In that case, you have a problem.
>
>"%d" is telling scanf to read an integer value. To do that, the next
>parameter must be the *address* of an int.
>
>scanf( "%d", &numberofns );

AHA, must it? See, that wasn't obvious from browsing over some of the
example code I've seen, but now you say it I can see &'s everywhere!
Now I need an explanation of WHY this is so and how to use the
variables via the addresses. Google is my friend. I'm really trying to
understand the basics before I go anywhere else.


>So to revise my earlier comment:
>
>If you are reading a single integer into an int, there's no need to mess
>with ASCII values, just compare with 0 and 9.

Thank you.

>>>> 2. Below is an INCOMPLETE function, but can you telL me why I'm
>>>> getting the compiler error "syntax error before '{' token" on the line
>>>> marked<<< please? Whats wrong with my declaration?
>>>>
>>>> //Declaration
>>>> int Fcheckinput ( int Vnumberofns ); // Validates input
>>
>>> Get rid of the spurious leading capitals, they only serve to confuse the
>>> reader.
>>
>> I'm using them to show me where I'm looking at a Function or Variable.
>> I'm sure I'll develop a personal style in the long term.
>
>Get used to using names that tell you whether you are looking at a
>function or variable. Use nouns for variables and verbs for functions,
>which you have done.
>
>Two common naming conventions are using underscores : check_input and
>mixed case: checkInput.

I don't like the underscores purely because of the two handed key
input. Lazy? Me?

http://www.cprogramming.com/tutorial/style_naming_conventions.html

Thanks to you and others who have replied. I'm now one small step
closer to the horizon.

Mike.