+ 3
Why function gets() doesn't work in a playground code? It's about C.
I've just tried to write some code on C in playground. But compilier said that he didn't know such function (gets()). studio.h and string.h was included.
9 Réponses
+ 3
You should use fgets()
Read this to know why not use use gets():
http://www.cplusplus.com/reference/cstdio/gets/
and here,
http://www.cplusplus.com/reference/cstdio/fgets/
on how to use fgets().
edit:
ahhhh.....Link does not show how to use the function for user input..so
char name[20]
fgets(name, 20, stdin);
+ 1
Can we see the code?
It's works but not recommended to use. Since it is couse misleading results when overflows..
So better to use fgets() instead of gets().
+ 1
Here the code. I think gets more convenient in this case.
+ 1
Yes I now about disadvantages of using gets () vs fgets (). But sometimes gets more convenient.
+ 1
In the code...when your multiplying, you've got what look like an 'x' instead of a '*'...also.....
for (i=0;i<=strln; i++){
blah blah
}
should be:
for (int i=0;i<=strln; i++){
blah blah
}
and the gets()
Apart from that....it works.
+ 1
And There are other errors..
for (i=0;i<=strln; i++){ //here i is undefined..
So Add int i instead of i only..
Line 24, 25 : unnecessary extra white-spaces, I deleted,
And you used x instead * for multiplication..
I edited all these errors..
It's working...
char output[strln+1+(2*z)];
output[strln+1+(2*z)]='\0';
+ 1
Oh yeah. Thanx a lot. It works! 👍
+ 1
Never use gets(). You’re asking for bugs that take weeks to track down, that are so easily avoidable.