I want to make an array that contains strings... how do I go about this? For example, in Perl I would type:
@bleh = ("bleh", "blah", "heh", "haha")
That's what I want... an array with strings... but in C. And how do I declare it?
Printable View
I want to make an array that contains strings... how do I go about this? For example, in Perl I would type:
@bleh = ("bleh", "blah", "heh", "haha")
That's what I want... an array with strings... but in C. And how do I declare it?
char mystring[len][numwords];
always worked for me
Does anyone know any tutorials that cover C programming REALLY well... like everything in really great detail. I'm mostly looking for more on strings and arrays. I need a few that are really detailed. Thanks in advance!
char cMyArray[2] = {"ok","bye"};
you can't store "ok" and "bye" in a character...
Code:#include <string>
using namespace std;
void main(){
string str[2] = {"ok", "bye"};
}
I would try to avoid using 2 dimensional character arrays for strings.
Make use of the CString library available.
CString works for one string, CStringArray works for an array of CString's. If you need more information just ask and I'll be glad to help you out.
USE the STL string over a CString, as the STL string will be availible with just about any compiler that is worth its salt.
Z.
CString is also only available with either MFC or ATL, both of which will press you into a predetermined application scheme.
Probably not what you want.
Use the STL string, maybe the STL vector (some people have problems using a vector of strings).