Presentation is loading. Please wait.

Presentation is loading. Please wait.

5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A.

Similar presentations


Presentation on theme: "5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A."— Presentation transcript:

1 5.6 String Processing Part 2

2 Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A terminating null character is automatically appended after the content.

3 Sprintf()

4 The following built in functions become available when you include #include at the top of your program

5 Strcpy(destinationvar,sourcevar) Copy string Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).

6 Strcpy()

7 Strcat(destinationvar,sourcevar) Concatenate strings Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination. destination and source shall not overlap.

8 Strcat()

9 Strncat(dstnvar,srcvar,num) Append characters from string Appends the first num characters of source to destination, plus a terminating null-character. If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.

10 Strncat()

11 Strcmp(s1,s2) Compare two strings Compares the C string str1 to the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.

12 Strcmp(s1,s1) Return Value – Returns an integral value indicating the relationship between the strings: A zero value indicates that both strings are equal. A value greater than zero indicates that the first character that does not match has a greater value in str1 than instr2; And a value less than zero indicates the opposite.

13 Strcmp(s1,s2)

14 Strlen(stringvar) Get string length Returns the length of the C string str excluding Null Character This should not be confused with the size of the array that holds the string. For example: char mystr[100]="test string";

15 Strlen(stringvar)

16 Practice Write a Simple Text based RPG that uses some of the built in functions that we talked about.


Download ppt "5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A."

Similar presentations


Ads by Google