Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
C and C based languages module C206
Character Strings
Exercises, examples and other material relating to training module C206. This topic is presented on public courses Learning to Program in C, Learning to program in C and C++, Programming in C, C and C++ Programming, Learning to program in C and C++, C and C++ Programming

Background
As well as doing calculations on numbers, you'll want your program to be able to handle strings of text - things like names and addresses and product codes ... and HTML tags and SQL queries too, perhaps. C defines strings as char[] types, and there's a whole raft of standard functions that are available to work on strings.
Articles and tips on this subjectupdated
4633String handling in C - new examples of extracting integers from a string
A new example in C, reading in a line of text and parsing all the integers from it into an array - [here]. It uses   fgets to read a line from the user   strdup to take a copy of that line   strsep to read up to the next separator   strtol to convert a string to ...
2016-01-27
 
4556Strings in C - strncmp strncpy and friends
Strings in C are pointers to arrays of characters, null (\0) terminated. Which means that if you compare them with the == operator, you're going to be comparing addresses, and not whether the strings contain the same text. And even if you put a "*" in front of the variable you're comparing, all you'll ...
2015-10-27
 
4340Simple C structs - building up to full, dynamic example
During the final day of our "Learning to program in C" course - today - we built up an example that introduced structs, then added dynamic memory allocation so that we ended up with a flexible program capable of taking an unlimited amount of data. The build up examples also show (in the last program) ...
2014-12-03
 
3718Splitting a record into individual data values in C
Many data files consist of a number of records, each of which is divided into a number of fields. How do you handle such data records in a C program? You could use very low level string handling functions, but it's probably far better to step up one level and use something like the string tokeniser. ...
2012-05-05
 
3593Chars, char arrays and strings in C. Some early cautions and pitfalls.
A char in C is a single byte variable, and a string in an array of chars (i.e. a series of chars held in successive memory addresses) and terminated by a null (\0). Because of this need for a terminator, you need to allocate one ADDITIONAL byte of memory / character position than the maximum number ...
2012-01-28
 
3144Setting up arrays in C - fixed size at compile time, or dynamic
You can store a whole series of data values of the same type in an array in C. The easiest way to declare an array is something like:   int history[20]; and that will give you an array of 20 elements - which you can refer to as elements number 0 to 19, so:   history[4] = 1234; to ...
2011-01-25
 
3146Strings in C
Strings in C are null terminated char arrays ... so you always need to allocate one more array member for them than the maximum possible length - to hold a string of up to 20 chars, you need an array of 21. Double quoted string constants are null terminated strings, and if you assign them to a variable, ...
2011-01-25
 
3122When is a program complete?
"Code is never completed ... it can always be improved." ... it's one of the most difficult aspects in many projects to say "yes, that does what we want and we should go for a release now rather than continuing to develop until ... until it's so late that we've missed the boat / added too much complexity ...
2011-01-08
 
2844Learning about Regular Expressions in C through examples
Although we more usually teach Regular Expressions on courses on Perl, Python, PHP, Ruby, etc ... there is also a standard C library, which uses the POSIX flavour of regular expressions, and I've put a short example together to "show you how". Firstly - what is a regular expression? It's a "pattern ...
2010-06-30
 
2843String functions in C
A String is a NUL terminated array of chars. Remember to allow space in the string for the NUL, and for any new line character you may have too, if you dimension it manually. And remember to add a NUL back on to the end if you extend a string by adding individual characters to it. There are lots of ...
2010-06-30
 
1338Handling Binary data in Tcl (with a note on C)
In Tcl, all variables are held as strings, and most of the commands will split / divide strings at new line or space characters by default. However, there are a few commands that do NOT make that distinction and since a Tcl string (Unlike a C string) may contain any bit pattern at all, they provide a ...
2007-09-11
 
Examples from our training material
ccis.c   Basic string and command line handling
chout.c   Strings v chars
cli.c   Command Line Handling
cli2.c   Command line - use of pointers example
cli3.c   Command line params - more complex character string arrangement
cli4.c   Picking out command line options into an array
cli5.c   More advanced coding style to handle argv and argc
cs1.c   Comparing strings in C
csame.c   Comparisons of strings in C
cstr.c   String manipulation in C
cx.c   String copying and manipulation
dynamic.c   memory allocation and release with calloc and free
dynbad.c   How NOT to do it - overrunning an array
fff   Some sample data
lynebreak.c   Tokenising a C string
makefile   makefile for module C206
p021.c   String handling examples
p022.c   parsing and checking integers off a line
p023.c   read an array of numbers from a text string
pothat.c   Strings via pointers and arrays of chars
rabbit.c   Structures and file i/o - C
range.c   Summing numbers from the command line
readwrite.c   File handling basics in C
reg.c   Regular Expression matching in C
reg2.c   Match and Capture - Regular Expressions
s1.c   String compare and copy
s4.c   Read lines from file, tokenise them, save data into an array of structs.
sti1.c   Characters and strings in C
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
Defining string variables
String manipulation functions
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/C206.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat