Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Whats wrong with the following function

char *string()
{
char *text[20];
strcpy(text,"Hello world");
return text;
}

Answer Posted / avinash

In this question ,two wrong thins ----
1.this is an array of char pointer so use
strcy(text[no.],"Hello World");

2.
we are copying a string without allocating memory to pointer . This is bug code .

correct solution :----

char *string()
{
char *text[20];
text[0]=malloc(20*sizeof (char));
strcpy(text,"Hello world");
return text;
}

Is This Answer Correct ?    15 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c procedural or object oriented?

953


What do the functions atoi(), itoa() and gcvt() do?

1137


Under what circumstances does a name clash occur?

1157


What is a string?

1052


Explain how do you view the path?

1087


how we can make 3d venturing graphics on outer interface

4731


Why is C language being considered a middle level language?

1043


What are pointers? What are stacks and queues?

1064


Explain what is a const pointer?

1036


What is a pointer on a pointer in c programming language?

1092


When do we get logical errors?

1072


What do you mean by a local block?

1027


write a c program in such a way that if we enter the today date the output should be next day's date.

2137


Explain how do you generate random numbers in c?

1043


What are all different types of pointers in c?

958