From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) Newsgroups: comp.os.msdos.djgpp Subject: Re: Help with strings MID$? Date: 29 Aug 1997 08:31:35 GMT Organization: The National Capital FreeNet Lines: 46 Message-ID: <5u61d7$97d@freenet-news.carleton.ca> References: <01bcb3ea$4e6e4560$6889d2cd AT inventor DOT worldchat DOT com> Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) NNTP-Posting-Host: freenet2.carleton.ca To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk "Vincent Collura" (inventor AT worldchat DOT com) writes: > Hello, > > I am new to C++ and am trying to convert a > old QuickBasic utiltiy I wrote into C++. It > compiles fine except I still cant figure how > to convert this Basic statement > > tally(item) = MID$(touch$, 2, 5) + MID$(touch$, 41, 12) + MID$(touch$, 73, > 7) > > Into c++, For those who dont know, mid$ returns the > n'th character to the nth number. > > What is the C++ function to do this? I have > tried StrnCat but the problem with this is you > cant specificy a starting location. Easy. You can, using pointers (which basic lacks, or hides very well anyways.) char touch[256]; // touch$ (a string in C/C++ is an array of chars) char tally[NUM_ITEMS][256]; // tally, an array of these arrays char *temp; // Pointer temp=touch+1; // touch is also a pointer to the first character of // touch$. temp is one past that: the second character. tally[item][0]=0; // Strings have a 0 char at the end as delimiter; this // makes the first char of the string tally[item] null, // making it an empty string. strncat(tally[item],temp,5); // The above 2 lines could be replaced with strncpy(tally[item],temp,5); temp=touch+40; // 41st character of touch$ strncat(tally[item],temp,12); temp=touch+73; strncat(tally[item],temp,7); Note that this is more a C/C++ than DJGPP-specific issue, and might be better placed in comp.lang.c or comp.lang.c++. (The above works in C or C++.) -- .*. Where feelings are concerned, answers are rarely simple [GeneDeWeese] -() < When I go to the theater, I always go straight to the "bag and mix" `*' bulk candy section...because variety is the spice of life... [me] Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh