Strings Flashcards
When does null terminator need to be included in a string?
Using string functions
‘\0’
NULL Terminator
strlen argument(s)
char *
What does strlen return?
Int; Index of first NULL Terminator
What should you do instead of
while (i < strlen(str)) {
…
}
while(str[i] != ‘\0’) {
…
}
Find length of string
strlen
strcpy arguments
2 char *s; destination, source
What does strcpy return?
char *; pointer to destination
Given strings a and b, what should you do instead of:
a = b;
strcpy(a, b);
Store word “Apple” into string str
char str[5+1];
strcpy(str, “Apple”);
Joins two strings together in c.
strcat
strcat arguments
2 char *s; destination and source
What does strcat return?
char *; destination
Mnemonic way to think about strcpy
strcpy(a,b) is a = b
Mnemonic way to think about strcat
strcat(a,b) is a += b