string functions Flashcards
What are examples of array initialization in C and how does it differ from Java?
int a[10]; int a[] = {1,2,3} in Java an array was descried like this: int[] a = {1,2,3}; int a = new int[]; AND you don’t need to use new
What is the terminating character for Strings? (in C) How does it affect the size of the char array?
‘\0’ The character uses up one of the spaces of the length
What does int strlen(s) do?
returns length of string s unit \0
What does strcpy(dst, src) do?
copies string characters from src into dst
What does: char* strdup(s), do?
allocates and returns a copy of s
what does: strcat(s1, s2), do?
Concatenates s2 onto the end of s1 (puts \0)
What does: int strcmp(s1, s2), do?
returns < 0 if s1 comes before s2 in ABC order returns > 0 if s1 comes after s2 in ABC order returns 0 if s1 and s2 are the same
what does: int strchr(s, c), do?
returns index of first occurrence of c in s
What does: int strstr(s1, s2), do?
returns index of first occurrence of s2 in s1
What does: char* strtok(s, delim), do?
breaks apart s into tokens by delimiter delim
what is the difference with: strncpy, strncat, strncmp
lengh-limited version of above the same functions?