On 2/15/07, shahwalishaik <[EMAIL PROTECTED]> wrote:
> I've attended an interview few days back. The qeustion paper had
> some programs. There's a bug in it, and we need to find it. Please,
> help me find the bug.
>
> #include<string.h>
> #define MAX_STRING 80
> char *Funct(char *p1, char *p2)
> {
> char str[MAX_STRING+1];
> int 1;
>
> str[MAX_STRING] = '\0';
> 1=strlen(str);
> strncat(str,p2,MAX_STRING-1);
> return str;
> }
>
>
> [mod - There's more than one bug. Simply putting this code through a compiler
> would show you some syntax errors - you cannot use the numeral one as a
> variable name (the
> int 1; and
> 1=strlen(str);
> lines. A runtime error is the potential buffer overrun in the call to
> strncat() - PJH]
The function also returns the address of the local str variable.
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi