Whats wrong with the following function

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

Answer Posted / vignesh1988i

as for as i know , there is only one error..... you have
declared text as array of pointers and not as character data
array..... so this text can only accept addresses.... :)

char *text[20] means you are going to store 20 addresses in
this array..... When you store addresses using arrays , the
that is called array of pointers....

if u declare : char text[20] , this will work correctly..



thank u

Is This Answer Correct ?    13 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the advantage of a random access file?

738


What are the complete rules for header file searching?

759


What is define directive?

723


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

5084


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

825






In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

843


What kind of structure is a house?

643


What is the right way to use errno?

718


What are the applications of c language?

732


What are structure members?

679


How can you tell whether a program was compiled using c versus c++?

711


What are the preprocessor categories?

715


PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE

1567


How would you rename a function in C?

705


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

1943