473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

one question about string

7
I want to write function that take array of strings and return to me one string that contain all of the words i passed to this function
i have problem with how to pass to function (prototype)

here is the main :

void main()
{
char *words[]={{"a"},{"picture"},{"is"},{"worth"},{"a"},{"thous and"},{"words"}};


char *word=sentence(words);
puts(word);

}

and the prototpye of sentence function is like this

char *sentence(char ** words);

is it ok? or wrong and how can i get the first word
is it *words[i] ?
best regards
Oct 31 '08 #1
3 1093
You CANNOT make a function return a string or or any array. What you can do is pass a one dimensional array of charachters as another parameter to the function and alter it inside this function, and make the return type void( void sentence(char ** words,char *word) ). But there isn't anything else wrong.
Oct 31 '08 #2
donbock
2,426 Expert 2GB
1. Function sentence has no way of inferring the dimension of the passed array. That's why, for instance, the standard prototype for main has the argc argument.

2. You're declaring variable word with an initializer, but the value of the initializer isn't known until run-time. Don't know about C++, but you can't do that in C. Separate the declaration from the assignment.

3. Realize that if you declare word as a char* then it will only be a pointer. That leaves it up to somebody else (sentence?) to allocate the memory needed to hold the concatenation of all the strings in the words array.
Oct 31 '08 #3
omryk
7
tnx but is it the same solution as u offered in C and C++ or maybe in C++ i can do something else?
Oct 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
14
by: key9 | last post by:
Hi All On coding , I think I need some basic help about how to write member function . I've readed the FAQ, but I am still confuse about it when coding(reference / pointer /instance) , so I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.