Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MindWipe

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

This topic is 6934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!