Discussion:
using the function "gets",and a problem on integration
(too old to reply)
Hammad Imad
2004-01-23 04:06:09 UTC
Permalink
i used the function "gets" in my program and once making the file, it says
gets is a dangerous function and should not be used.

I asked the prof about it, he said that he was aware that it produces a
warning and we shouldnt worry about it but not an error.He did say he
wuld get back to me but i havent had a class with him since.

So does anyone know how to fix that

My other problem is with the integration lab part.In the functions a
pointer *P to the array is passed. Im not sure if im operating on it
properly.i am typing

answer+= P[i] * power;

is the way im referencing P incorrect? is that why my program isnt
working or no?

Thank you very much
Alexander Smith
2004-01-23 15:23:09 UTC
Permalink
(Scroll down.)
Post by Hammad Imad
i used the function "gets" in my program and once making the file, it says
gets is a dangerous function and should not be used.
I asked the prof about it, he said that he was aware that it produces a
warning and we shouldnt worry about it but not an error.He did say he
wuld get back to me but i havent had a class with him since.
So does anyone know how to fix that
It would be better to use something like:
scanf("%s", word);
instead. (There are differences: scanf will only read one word, whereas
gets() will give you the whole line, but you can assume the user will only
enter one word anyways.) For a discussion of why gets() is "dangerous",
see my message from Jan 11 "Re: lab0 error".
Post by Hammad Imad
My other problem is with the integration lab part.In the functions a
pointer *P to the array is passed. Im not sure if im operating on it
properly.i am typing
answer+= P[i] * power;
is the way im referencing P incorrect? is that why my program isnt
working or no?
That looks like a reasonable piece of code. If that isn't working for you,
then you probably have a bug somewhere else in your function.
Post by Hammad Imad
Thank you very much
Please be careful when posting code on the lab. The last line of code you
posted very, very close to being unacceptable for the newsgroup. In this
case, that's mostly because the function you're writing is simple, and
there aren't really that many different ways of doing it. However, in the
future, avoid copying code directly from your lab whenever possible. If
you're not sure, e-mail it directly to me instead, and I'll answer your
question through e-mail instead of on the newsgroup.

Alexander

Continue reading on narkive:
Loading...