Problem with gets()

I am using xCode on mac os x 10.5.4. I used gets() for a certain code but it's not working on the built-in console of xCode named gdb and it also showing an warning message like this 'warning: this program uses gets(), which is unsafe'. But it works fine when I run it into the terminal window though the warning is still there.

can anyone please tell me how do I resolve this problem?

Is there any IDE for c++ with compiler(if it does not share from xCode or gcc whatever is installed) or without compiler(if it does) for mac os x 10.5.4 which is as simple as Microsoft Visual C++(as I am familiar with that)?
First off:

The compiler is correct; gets() is unsafe.

Post your code, please, so that we may suggest an alternative.
My code is given bellow:

#include<stdio.h>
#include<string.h>

char mat[35][85];
int len[35];

int main() {
int n, i;
while(gets(mat[0])) {
len[0] = strlen(mat[0]);
n = 1;
while(gets(mat[n]) && mat[n][0] != '_') {
len[n] = strlen(mat[n]);
n++;
}
for(i = 0; i<=n; i++)
printf("%s\n", mat[i]);
}

return 0;
}

and the input will be like this:

XXXXXXXXXXXXXXXXXXXX
X X X
X # # XXXXXXXX / X
X X X
XXXXXXXXXXXXXXXXXXXX
_____________________________


Is it possible to test the code in xCode's built-in console as it works in the Terminal? If yes, how and if no, why?
Last edited on
Topic archived. No new replies allowed.