473,387 Members | 1,572 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,387 software developers and data experts.

need help on string array

Hello
I have to create an array of string(rowname) such that
rowname[0] = "c1",rowname[1] = "c2",............................................. ..........
rowname[NUMROWS+1] = "NUMROWS"
I have written this part of code as
Expand|Select|Wrap|Line Numbers
  1.     char **rowname = new char*[NUMROWS] ; 
  2.     char row = 'c' ;
  3.     char str[20] ;
  4.  
  5.     for(i=1;i<=NUMROWS;i++)
  6.     {
  7.         sprintf(str,"%c%d",row,i);
  8.     }
  9.  
How can i link str with rowname.
I tried
Expand|Select|Wrap|Line Numbers
  1. rowname[i] = str ;
  2. rowname[i] = &str ; 
  3.  
But nothing works, can anyone suggest some way to do this.

Thanks
Abhishek
May 19 '07 #1
1 1138
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. char **rowname = new char*[NUMROWS] ; 
  2.  
has created an array of char*. That means rowname[0] can point to a string.

However, you need to allocate memory for the string first.

Expand|Select|Wrap|Line Numbers
  1. rowname[0] = new char(strlen(str) + 1];
  2. strcpy(rowname[0], str];
  3.  
and then copy str to the allocation.
May 20 '07 #2

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
2
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
3
by: David P. Donahue | last post by:
I'm trying to come up with the best (fastest, as this code will be run often) way to accomplish the following: I have a dynamic string array X (as one grabbed from a GetFiles() or...
4
by: ayman723 | last post by:
hi, I'm trying to write a program in wich I would generate 20 sentences out of 4 arrays(articles,nouns,preposition,verb).I have to select an item at random from each array and concatetane each one...
0
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: pob | last post by:
I was all happy because thru some tutelage of others I created this array to find the newest file in a directory. However, I then realized its great that I now know the latest file, but I need to...
3
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display an array of objects using a GUI. My instructions are that the CD class and it's sublcass don't need to change I just need to modify class CDInventory to include the GUI. I'm not...
3
by: jac130 | last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.