CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Strings are 1-dimensional arrays of characters

In contrast to some other programming languages, C does not have a basic datatype for strings.

However, C compilers provide some basic support for strings by considering strings to simply be arrays of characters.

We've already seen this support when calling the printf() function:

   printf("I'm afraid I can't do that Dave\n");

The double quotation characters simply envelope the characters to be treated as a sequence of characters.

In addition, a standards' conforming C compiler is required to also provide a large number of string-handling functions in its standard C library. Examples include:

#include  <string.h>

// which declares many functions, including:

  int strlen( char string[] );                         // to determine the length of a string

  int strcmp( char str1[],  char str2[] );             // to determine if two strings are equal

  char *strcpy( char destination[],  char source[] );  // to make a copy of a string

In reality these functions are not "really" managing strings as a basic datatype, but are just managing arrays of characters.

 


CITS2002 Systems Programming, Lecture 5, p5, 5th August 2024.