Thursday, September 15, 2016

Digest for comp.lang.c++@googlegroups.com - 1 update in 1 topic

David Brown <david.brown@hesbynett.no>: Sep 15 11:20PM +0200

On 15/09/16 22:26, Vir Campestris wrote:
 
> while( fgets( eingabe, sizeof eingabe, stdin ))
> if( sscanf( eingabe, "%d", &wert )!= 1 ) {
> - { fprintf( stderr, "Please enter a number!\n" );
 
I think you've got an extra bracket in there.
 
 
> and git blame would blame me for using fprintf in a C++ programme.
 
> (I don't like Git - but we use Android, so I'm stuck with it. And some
> of the time I'm stuck with Linus' coding standards too :( )
 
I prefer the "One true brace style", as well as always including braces
in conditionals. So I would write:
 
 
while (fgets(eingabe, sizeof eingabe, stdin)) {
if (sscanf(eingabe, "%d", &wert) != 1) {
fprintf(stderr, "Please enter a number!\n");
} else {
summe += wert;
}
}
 
And after the change, it would be
 
while (fgets(eingabe, sizeof eingabe, stdin)) {
if (sscanf(eingabe, "%d", &wert) != 1) {
fprintf(stderr, "Please enter a number!\n");
+ ++errcount;
} else {
summe += wert;
}
}
 
Then git would only blame me for the change I actually made.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: