English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How can I copy a string (array of character) to an array of string such as:

char text[a][b];

wherein a is the index number of the array and b is the max length of array of characters that can be stored in the array..

For example I have an array of characters "char word[20];"
How can I store it to an array of strings "char text[99][20];"??

Please help.. And thanks..

2007-02-23 20:36:50 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

you can use the strcpy() function.

strcpy(text[99], word);

or:
for (int a = 0; a < 20; a++)
{
text[99][a] = word[a];
}

both will work.

2007-02-24 02:14:57 · answer #1 · answered by justme 7 · 0 0

for (int x=0; x<20; x++)
{
text[0][x] = word[x];
}

// This will copy the char array word into the first row in text.
// word is a one dimensional array.
// text is a two dimensional one.

2007-02-23 20:48:09 · answer #2 · answered by John Galt 2 · 0 0

it is C-String issue , As each and every physique suggested , you won't be in a position to resize c-strings, yet could nicely be solved making use of as : char *FirstName = char[20]; // could be-> char FirstName[20]; std::cin.getline(FirstName,20); int length = strlen(FirstName); //strlen seems for '0' for end of string char*editFirstName = new char[length+a million]; strcpy(editFirstName, FirstName); i could advise you to apply C++ Strings , i.e std::string. you're able to do some thing like : std::string FirstName; std::getline(FirstName,'n'); // no could resize FirstName now and quite person-friendly to apply. you're accomplished)

2016-12-17 17:43:31 · answer #3 · answered by ? 4 · 0 0

Yes it is possible!!
Wat U need to do is that for example
let


char word[5]={'a','b','c','d','e'};
char test[20][10];
for(i=0;i<5;i++)
{ {test[p][q]=word[i];
q++;}
if(q==10)p++;
}


Ok Gud LC Bye

2007-02-23 21:08:00 · answer #4 · answered by amit chat 2 · 0 1

fedest.com, questions and answers