From: Paul Bibbings on
Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:

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

It certainly seems like an oddly randam rejection of a common
convention; unless, of course, you have a keyboard that otherwise
permits `one-handed' input of !, ", %, ^, &, *, (, ), +, {, }, :,
~, <, > and ?. Or will you not be using these either? ;-)

Regards

Paul Bibbings
From: Mike Barnard on
On Sun, 09 May 2010 12:05:18 +0100, Paul Bibbings
<paul.bibbings(a)gmail.com> wrote:

>Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:
>
>>
>> I don't like the underscores purely because of the two handed key
>> input. Lazy? Me?
>
>It certainly seems like an oddly randam rejection of a common
>convention; unless, of course, you have a keyboard that otherwise
>permits `one-handed' input of !, ", %, ^, &, *, (, ), +, {, }, :,
>~, <, > and ?. Or will you not be using these either? ;-)

Aha, if it doesn't already exist I see a niche in the market for a
programmers keyboard!

This_is_a_variable. Thats three underscores, by the number of times
the variable is used. != is only one shift keystroke for example. I
think I might find out how to make the underscore replace another key.
Which one is the dirtyest, the least touched!
From: Paul Bibbings on
Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:

> On Sun, 09 May 2010 12:05:18 +0100, Paul Bibbings
> <paul.bibbings(a)gmail.com> wrote:
>
>>Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:
>>
>>>
>>> I don't like the underscores purely because of the two handed key
>>> input. Lazy? Me?
>>
>>It certainly seems like an oddly randam rejection of a common
>>convention; unless, of course, you have a keyboard that otherwise
>>permits `one-handed' input of !, ", %, ^, &, *, (, ), +, {, }, :,
>>~, <, > and ?. Or will you not be using these either? ;-)
>
> Aha, if it doesn't already exist I see a niche in the market for a
> programmers keyboard!
>
> This_is_a_variable. Thats three underscores, by the number of times
> the variable is used.

So, that's three shifts. About the same for the other widely-used
convention:

thisIsAVariable

Or are you preparing to join the `thisisavariablewithaverylongname'
school of programming?

> != is only one shift keystroke for example.


> I think I might find out how to make the underscore replace another
> key. Which one is the dirtyest, the least touched!

From what we've gathered already, I would say that that would be the
SHIFT key! :-)

Regards

Paul Bibbings
From: Francis Glassborow on
Mike Barnard wrote:
> Hi all.
>
> I hope there's a few here still? These newsgroups are bleeding away.
>
> I'm trying to use online tutorials to teach myself C. (I'm starting
> with the basics before eventually trying for Objective C.) I have
> Code::Blocks compiler installed on my XP machine and I'm trying to
> create a few functions ATM.
>
> One function is to be a validator of input. I want a user to enter 1
> to 9 only. I want to get the character from a scanf() and compare it
> with the ascii table. If it's < 49 OR it's > 57 then returns are set
> else return = 0.
>
> 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.
>
> 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...
> }
>
> int Fcheckinput ( int Vnumberofns ); // Validates input
> { <<<
> int ns = Vnumberofns ; // put argument into internal variable.
> if ( ns < 49 ) // Compare it with ascii values.
> {
> return 1;
> }
> else if ( ns > 57 )
> {
> return 2;
> }
> }
> // ASCII
> // 0 - 47 are misc characters
> // 48 = 0
> // 57 = 9
> // 58 + are characters.
>
>
> Many thanks.
>
> Mike.
>

OK I have read the responses and none of them seem to tackle what I
consider to be fundamental. How to get a single digit from the keyboard.
Here is some simple code from me that you might like to consider.

int validate_input(char c){
int temp = c-'0';
if(temp < 0 || temp > 9){
puts("Your input was not one of the digits from 0 to 9\n");
temp = -1;
}
return temp
}

int main(){
char c;
int i;
scanf("Input a single digit and press return. %c", &c);
i=validate_input(c);
if(i == -1) // do whatever you want with invalid input
else // do whatever you want with valid input
return 0;
}

And before you all start howling, I would not actually use that code not
least because I do not use arbitrary constants without making them
manifest. I would also use such library functions as isdigit() for this
special case. We also need to clear the keyboard buffer to cover cases
where the user has typed in more than one character before pressing return.


However the principle point is that when validating input we have to get
characters and process them (otherwise we need to know how to deal
with rejected input that sits clogging the keyboard buffer)

Finally, I am curious as to why the poster is learning C if he wants to
use Objective C. Furthermore, why is he planning to learn Objective C
which is a language that is very little used outside the Apple Mac world?
From: Paul Bibbings on
Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:

> On Sun, 09 May 2010 12:05:18 +0100, Paul Bibbings
> <paul.bibbings(a)gmail.com> wrote:
>
>>Mike Barnard <m.barnard.trousers(a)thunderin.co.uk> writes:
>>
>>>
>>> I don't like the underscores purely because of the two handed key
>>> input. Lazy? Me?
>>
>>It certainly seems like an oddly randam rejection of a common
>>convention; unless, of course, you have a keyboard that otherwise
>>permits `one-handed' input of !, ", %, ^, &, *, (, ), +, {, }, :,
>>~, <, > and ?. Or will you not be using these either? ;-)
>
> Aha, if it doesn't already exist I see a niche in the market for a
> programmers keyboard!
>
> This_is_a_variable. Thats three underscores, by the number of times
> the variable is used. != is only one shift keystroke for example. I
> think I might find out how to make the underscore replace another key.
> Which one is the dirtyest, the least touched!

Setting `humour' aside for a second response, it's worthwhile at this
early stage in your learning to give you the opportunity to evaluate for
yourself what is, perhaps, more common than you might imagine, and that
is the `ease-of-typing' school of programming. The following won't be
directly relevant to you as you are choosing to learn C, but even Bjarne
Stroustrup - the creator of C++, which originated from C via `C with
classes' - espouses in his important work `The C++ Programming
Language' (Special Edition, �C.13.5):

"The /typename/ keyword can also be used as an alternative to class
in template declarations:

template<typename T> void f(T);

Being an indifferent typist and always short of screen space, I
prefer the shorter:

template<class T> void f(T);"

This is not to question Stroustrup's choice here, nor even his reason
for so choosing, in this context. However, you will encounter the same
reasoning to varying degrees propping up the coding choices of
programmers of all levels of expertise and experience in contexts where
it matters more. In the example from Stroustrup his choice does not
affect readability, but you will likewise come across many instances
where it this is just the very quality of code that is sacrificed, and
to what? To saving a few keystrokes here and there?

As a beginner, I would want to suggest that you hold off choices based on
`laziness', as you put it in your case, until you have learnt enough to
be able to evaluate what /other/ consequences arise from such a choice.
Follow convention, /until/ your learning has reached a point where you
know enough to be able to work out where it might be abandoned without
impact upon other factors such as readability, ease of understanding
(and hence of maintenance), and the like.

To take the `lazy' view at *this* stage of your learning would be like
calling yourself a marathon running whilst walking casually across the
tarmac from the start to the finish line, or, as a racing driver, to
prefer the cut across the grass verge to the chicane, or as a lover, to
woo with "come on love, let's get this over with!" In all such cases,
something is inevitably lost.

Regards

Paul