Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Strings

Node:Strings, Next:, Previous:Arrays, Up:Top



Strings

Communication using arrays.

So far we have examined variables that can contain integers, floating-point numbers, and values that represent individual text characters. But what if you need a variable that can contain a sequence of text characters, such as a name in a database of diners at a restaurant, as in the examples for last chapter? That's where strings and string variables come in.

A string value is a sequence of text characters that can become a value for a string variable. Both a string value and a string variable can be referred to as a string, depending on context.

In C, a string value is represented by text characters enclosed by double quotes:

"This is a string value."

A string can contain any character, including special control characters, such as the tab character \t, the newline character \n, the "bell" character \7 (which causes the terminal to beep when it is displayed), and so on.

We have been using string values since we introduced the printf command early in the book. (See The form of a C program.) To cause your terminal to beep twice, include the following statement in a C program:

printf("This is a string value. Beep! Beep! \7\7");

 
 
  Published under free license. Design by Interspire