Strings
Strings
1. strcpy : strcpy copies a string, including the null character terminator from
the source string to the destination. This function returns a pointer to the
destination string. Its prototype is :
5. strcmp : Two strings are compred with this function. If the first string is
greater than the second, it returns a number greater than zero. If the
second string is greater, it returns a number less than zero. If the strings are
equal, it returns 0. Its prototype is :
6. strncmp : This function compares the first N characters of each string. If the
first string is greater than the second, it returns a number greater than
zero. If the second string is greater, it returns a number less than zero. If
the strings are equal, it returns 0. Its prototype is :
7. strlen : This function returns the length of a string, not counting the null
character at the end. That is, it returns the character count of the string,
without the terminator. Its prototype is :
Arrays of Strings
An array of strings is just a two dimensional array of characters. Consider this :
n = read_intarray(exam_scores, MAX) ;
print_intarray(exam_scores, n) ;
The algorithm is very similar to our previous task, except that the details of
reading and printing the array is hidden by functions. The function,
read_intarray( ), reads scores and stores them, returning the number of scores
read. The function, print_intarray( ), prints the contents of the array. The refined
algorithm for main( ) can be written as : print title, etc.