Whats wrong with the following function
char *string()
{
char *text[20];
strcpy(text,"Hello world");
return text;
}
Answers were Sorted based on User's Feedback
Answer / 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 |
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 |
Answer / qint
1. returning address of a local variable.
2. wrong parameter passed to strcpy()
| Is This Answer Correct ? | 4 Yes | 5 No |
hOW Can I add character in to pointer array of characters char *a="indian"; ie I want to add google after indian in the char *a
Write a code to remove duplicates in a string.
Why c is a mother language?
What is a protocol in c?
Is r written in c?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
wat is the meaning of c?
what is the diff b/w static and non static variables in C. Give some examples plz.
code for selection sort?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?