I don't understand strings at all. I looked at the tutorial but I still don't get it...

Is there any tutorial that can be easily followed for inputting strings (no skimmers)?

-Superlox3

Recommended Answers

All 2 Replies

I don't understand strings at all. I looked at the tutorial but I still don't get it...

Is there any tutorial that can be easily followed for inputting strings (no skimmers)?

Explain:

  • What tutorial you read
  • Was it a C or a C++ string?
  • Is there something particular that you don't understand about strings?

Since you're Canadian I'll cut you lots of slack. :cheesy:

I don't understand strings at all. I looked at the tutorial but I still don't get it...

Is there any tutorial that can be easily followed for inputting strings (no skimmers)?

-Superlox3

When you think of a string what do you think of? A string of yarn? Some type of long, thin and circular materiel perhaps? Well in essence, a string can be thought of as a bunch of characters such as 'i' or 'a' - which are byte size - "stringed" together to form a word. Example:

Canada

Its corresponding representation in main memory would be something like this:

[ address 0 ][ C ]
[ address 1 ][ a ]
[ address 2 ][ n ]
[ address 3 ][ a ]
[ address 4 ][ d ]
[ address 5 ][ a ]
[ address 6 ][ 0 ]

The address of each value or character, byte character, would be sequential. So when you create a variable like char CN[]="Canada", all subsequent usages of CN will access this range of value; the 0 in the array would indicate the end of the string of characters that compose "Cananda".

There are char variables that hold only one character, and you can string a bunch of charaters to compose a string of characters. Also, it is helpful to remember that when you simply referrence CN by itself, it actually points to the first value in the array. To access any of the values in the array you'd simply use this syntax:

CN[Index_number]

For example, CN[0] would do the same thing as if you'd just use the CN and, CN[1] would access the second character in the string which is 'a'.

As mentioned before the '0' or '\0' is used to indicate the end of the string, used by many library functions and etc. Hoped I helped.

Good luck, LamaBot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.