Abort, Retry, Fail

Share this post

Intro to C, Part 8

www.abortretry.fail

Intro to C, Part 8

strings

Bradford Morgan White
Aug 30, 2012
Share this post

Intro to C, Part 8

www.abortretry.fail

So far, we have already covered the use of the character data type, but what happens when you want to print more than one character to screen? This was strings are for.

A string is a series of characters terminated as with a null character.

That is, a string is an array of characters.

An array is a series of pieces of data with an identical data type. You can have arrays of all types of numerals, characters, and even arrays.

#include <stdio.h>
int main(void) {
  char name[5];
  name[0] = 'F';
  name[1] = 'o';
  name[2] = 'r';
  name[3] = 'd';
  name[4] = '\0'; // this is the null character defining the end of the string
  printf("Hello, my name is %s\n", name);
}

One very important thing to note about this is that while our declaration declared five different elements, the counting of those elements starts at zero. We count zero through four, which is five total numbers.

Intro To C, Part 8 By Bradford Morgan White
359KB ∙ PDF File
Download
Download

Share this post

Intro to C, Part 8

www.abortretry.fail
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Abort Retry Fail LLC
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing