They are simply letters that stand for the kind of data type that will be inserted. The character specifiers are a little weird at first. This means we want two variables inserted into the output string. In this example, we have two format specifiers (%). The letter following the format specifier is called the format character, and it tells sprintf() what datatype will be used for that variable. The next argument is the string you want to create, filled in with format specifiers where you want to insert your variables. This is where you use the character buffer that you created on the previous line. The first argument is where you plan to store the string that sprintf() will be making for you. Note that sprintf() requires a minimum of 2 arguments. sprintf ( buffer, "The %d burritos are %s degrees F", numBurritos, tempStr ) The next line of code is the actual sprintf() function. Just count the characters you plan to store in that string and make sure the buffer is at least that large. The character array needs to be as large, or larger than the final output string. Let’s take a closer look at each line of code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |