Download presentation
Presentation is loading. Please wait.
Published byMaurice Gilbert Modified over 8 years ago
1
ENEE150 – 0102 ANDREW GOFFIN Strings
2
Project 2 Flight Database 4 options: Print flight Print airport Find non-stop flights Find one-stop flights 3 files: flights.txt airports.txt routes.txt Goffin – ENEE150
3
Strings In C, Null terminated array of characters Not a special datatype Last character in array MUST be ‘\0’ char str[8] = “strings”; Note how length is one longer than length of word “strings” Double quotes automatically append ‘\0’ Use “%s” flag in printf/scanf WARNING: Will also stop at spaces! Goffin – ENEE150
4
String Header File Relevant functions in string.h int strlen(char *s) Returns length of string s (DOESN’T include ‘\0’) void strcpy(char *s1, char *s2) Copies s2 to s1, including ‘\0’ int strcmp(char *s1, char *s2) Compares s1 and s2 and returns: 0 if the strings are the same Non-zero if strings are different Actual non-zero value is usually irrelevant Goffin – ENEE150
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.