On Wed, Mar 12, 2008 at 1:24 PM, xiaoxinchen1989
<[EMAIL PROTECTED]> wrote:
> this is a programe ,could you tell me why it can't run?Thank you!
>
>
>  #include<stdio.h>
>  #include<stdlib.h>
>  #include<string.h>
>
>  int main()
>  {
>     int n=10;
>     char* s=(char*)malloc(sizeof(char)*100);

Unnecessary and potentially dangerous casts, and redundant sizeof operation

>     char* s2=(char*)malloc(sizeof(char)*100);
>     itoa(n,s,10);

Non-standard function. Use sprintf() instead.

>     s2="*";

Memory leak; you've lost the pointer to the allocated memory - you
perhaps meant strcpy?

>     strcat(s2, s);

You are modifying a constant (read only) string - undefined behaviour.

>     printf("%s", s2);
>     system("pause");
>     return 0;

Missing calls to free()

>  }

What are you trying to do, to which this is your answer?

-- 
PJH

A man walks into a bakery, points and the girl behind the counter
"Is that a macaroon or a meringue?"
"No, you're right, it's a macaroon."

Reply via email to