Advertisement

I need some help with C++ (I'm a beginner)

Started by April 30, 2000 03:29 PM
3 comments, last by MindWipe 24 years, 7 months ago
I''m programming with DJGPP and Allegro. So keep in mind everything you know might not work for me. But how do I "analys" a string. I.e. "Building" how do I get the amount of letters from that string(8). And how do I read i.e. the 5th letter(d). In qbasic and VB it''s: len(string) for the lenght of the string and mid(string,x,y) x=where to start at the string, y= how many letters to read i.e. mid("House",3,2)="us" But how do I do it i c++?
"To some its a six-pack, to me it's a support group."
You can handle strings as array of char. But there are also some string functions in :
strlen(char *string) --> Length of string (must be 0 - terminated)
strcpy()
strcat()
..
if you want to get the 5th letter from a string like
char string[]
write
string[4]

Visit our homepage: www.rarebyte.de.st

GA
Visit our homepage: www.rarebyte.de.stGA
Advertisement
quote: Original post by MindWipe

In qbasic and VB it''s:

len(string) for the lenght of the string and
mid(string,x,y) x=where to start at the string, y= how many letters to read i.e. mid("House",3,2)="us"

But how do I do it i c++?


strlen(string) in C is equivalent to len(string) in BASIC.
mid(string, x,y) is a lot more complex. In order to -read- a substring in C, you would probably use strncmp (compare a given number of characters in 2 strings). But there''s no simple way to do the equivalent of this:
myVBString = "abCDef"mid(myVBString, 3, 2) = "cd"print myVBString ''will show "abcdef" 

I forget whether DJGPP is C or C++. If it''s C++, you might have better luck with the standard C++ string class, as that is better for working with. C doesn''t really handle ''strings'' as such, just arrays of characters, and therefore moving things around in the middle is a chore.

quote: Original post by Kylotan
But there''s no simple way to do the equivalent of this:
myVBString = "abCDef"mid(myVBString, 3, 2) = "cd"print myVBString ''will show "abcdef"  



I wouldn''t be so sure I have a string library that I wrote that rivals that of string.h (it has much cooler functions). If you want it, email me.



--------------------


You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Thanks! I''ll try without the special string.h.

I think I will manage
"To some its a six-pack, to me it's a support group."

This topic is closed to new replies.

Advertisement