Use gets Safely

B

Billy Bong

I wrote this program which guarantees to use gets safely.

#include <stdio.h>
int main(void)
{
char name[588+1];
printf("Enter your last name: ");
fflush(stdout);
printf("Hi %s\n",gets(name));
return 0;
}

You see, the longest last name in the world is 588 characters, as
explained here:

http://www.everything2.com/index.pl?node_id=1534419

So, my program works for everyone in the world. Guaranteed.
 
U

user923005

I wrote this program which guarantees to use gets safely.

#include <stdio.h>
int main(void)
{
   char name[588+1];
   printf("Enter your last name: ");
   fflush(stdout);
   printf("Hi %s\n",gets(name));
   return 0;

}

You see, the longest last name in the world is 588 characters, as
explained here:

http://www.everything2.com/index.pl?node_id=1534419

So, my program works for everyone in the world. Guaranteed.

What if they type in an extra ten letters, just for fun?

What if they feed it a 100 MB binary file?
 
W

Walter Roberson

I wrote this program which guarantees to use gets safely.
=A0 =A0char name[588+1];
=A0 =A0printf("Hi %s\n",gets(name));
You see, the longest last name in the world is 588 characters, as
explained here:
http://www.everything2.com/index.pl?node_id=1534419
So, my program works for everyone in the world. Guaranteed.
What if they type in an extra ten letters, just for fun?

Or if they have a typo in their own name (not unlikely in 588
characters).
 
C

Chris Dollin

Billy said:
I wrote this program which guarantees to use gets safely.

#include <stdio.h>
int main(void)
{
char name[588+1];
printf("Enter your last name: ");
fflush(stdout);
printf("Hi %s\n",gets(name));
return 0;
}

You see, the longest last name in the world is 588 characters, as
explained here:

http://www.everything2.com/index.pl?node_id=1534419

So, my program works for everyone in the world. Guaranteed.

Exactly how does it ensure that the user is constrained to enter
a genuine last name, and how does it ensure that the constraints
for a longest last name /still hold/ when it runs?

Nice try.
 
M

Malcolm McLean

I wrote this program which guarantees to use gets safely.

#include <stdio.h>
int main(void)
{
char name[588+1];
printf("Enter your last name: ");
fflush(stdout);
printf("Hi %s\n",gets(name));
return 0;

You see, the longest last name in the world is 588 characters, as
explained here:

So, my program works for everyone in the world. Guaranteed.
What if they type in an extra ten letters, just for fun?
What if they feed it a 100 MB binary file?
If you disobey instructions the program might not work. But that's true of
almost every product.
 
B

Bart C

Billy Bong said:
I wrote this program which guarantees to use gets safely.

The program can't guarantee anything. It's up to the user in this case, and
you can't guarantee what the user will do. But I think you knew that.

I tried your code (using name[5+1] instead to save some typing) with my full
name, and it crashed.

Bart
#include <stdio.h>
int main(void)
{
char name[588+1];
printf("Enter your last name: ");
fflush(stdout);
printf("Hi %s\n",gets(name));
return 0;
}
 
A

Antoninus Twink

Such style. Such grace. Such quality of argumentation.
The only thing missing is the obligatory "Neener, neener!".

Interesting to see Chris "holier-than-thou" Dollin getting his hands
dirty insulting the "trolls" though...
 
C

Chris Dollin

Antoninus said:
Interesting to see Chris "holier-than-thou" Dollin

I'm honoured, Antoninus, but I didn't realise you were qualified
to award holiness.
getting his hands dirty insulting the "trolls" though...

/That/ was mere snark.
 
A

Antoninus Twink

I'm honoured, Antoninus, but I didn't realise you were qualified
to award holiness.

Yes, that did end up sounding much too pejorative! I don't think you're
positively sanctimonius at all - it's just that unlike most of The
Clique you seem quite good-natured and good-humored, and don't usually
go in for the nastiness and acrimony that's the bread and butter of most
of the regulars here.
/That/ was mere snark.

Fair enough. You'd have to agree that CLC is actually one of the most
humorless places on Usenet though...
 
K

Kelsey Bjarnason

[snips]

If you disobey instructions the program might not work. But that's true of
almost every product.

Unlike most products, software can cope with such things. A toaster can't
prevent you sticking a fork in it while it's plugged in, even though this
is an undesirable state of affairs, but a program _can_ prevent you
entering incorrect inputs, by avoiding input routines such as gets, and by
validating the data returned by such routines.

Besides, much input to a typical program comes from humans, who are *not*
perfect in their typing, let alone anything else they do. A program which
fails to deal with this reality is doomed to endless errors. A programmer
who fails to deal with this reality is - one would hope - doomed to a
career path not involving software development.
 
R

Richard Bos

Malcolm McLean said:
user923005 said:
I wrote this program which guarantees to use gets safely.
char name[588+1];
printf("Hi %s\n",gets(name));
You see, the longest last name in the world is 588 characters, as
What if they type in an extra ten letters, just for fun?
What if they feed it a 100 MB binary file?

If you disobey instructions the program might not work. But that's true of
almost every product.

You clearly do not own a pet larger than a budgie, and do not have
little children. Nor do you read reference books while coding.

Richard
 
C

Chris Dollin

Antoninus said:
Yes, that did end up sounding much too pejorative! I don't think you're
positively sanctimonius at all - it's just that unlike most of The
Clique

I think the "clique" is an invention of its detractors.
you seem quite good-natured and good-humored, and don't usually
go in for the nastiness and acrimony that's the bread and butter of most
of the regulars here.

I think you are mistaken.
Fair enough. You'd have to agree that CLC is actually one of the most
humorless places on Usenet though...

I'm afraid I'm under no such obligation.
 
A

Antoninus Twink

I think the "clique" is an invention of its detractors.

A rose by any other name...
I think you are mistaken.

About your being good-natured, or about many regulars' being nasty and
acrimonious, or both?
I'm afraid I'm under no such obligation.

And in your heart of hearts?

Back to your point (when comparing the trolliness of Default Loser and
Chris Hills) about not only technical contributions being positive,
perhaps you could cite the odd example or two of recent posts from
"Brian" that you *do* consider positive?
 
R

Regan Revised

Antoninus Twink said:
A rose by any other name...


About your being good-natured, or about many regulars' being nasty and
acrimonious, or both?


And in your heart of hearts?

Back to your point (when comparing the trolliness of Default Loser and
Chris Hills) about not only technical contributions being positive,
perhaps you could cite the odd example or two of recent posts from
"Brian" that you *do* consider positive?
You rage against Heathfield and his infernal cohort yet do not avail
yourself of chp 8 of Unleashed.

Far funnier is that the Falconer posted a fix for gets, ggets, that
Heathfield had to fix from having a memory leak. Does Heathfield need to be
on everyone's speed dial to prognose memory mgmnt trouble in C?

--

Reagan Revision

To sum up: 1. The cosmos is a gigantic fly-wheel making 10,000 revolutions a
minute. 2. Man is a sick fly taking a dizzy ride on it. 3. Religion is the
theory that the wheel was designed and set spinning to give him the ride.
-- H L Mencken, "Coda," in Smart Set (New York, Dec. 1920; repr. in A
Mencken Chrestomathy, pt. 1, 1949).
 
A

Army1987

Billy said:
I wrote this program which guarantees to use gets safely.

#include <stdio.h>
int main(void)
{
char name[588+1];
printf("Enter your last name: ");
fflush(stdout);
printf("Hi %s\n",gets(name));
return 0;
}

You see, the longest last name in the world is 588 characters, as
explained here:

http://www.everything2.com/index.pl?node_id=1534419

So, my program works for everyone in the world. Guaranteed.
What if I fall asleep with my nose falling onto the spacebar?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top