printf

The function printf converts a sequence of values to strings in specified format and display the string. The first argument is a format string that contains all text that is to be printed literally and the formats in which the following arguments are to be converted. Each format specification starts with a % sign. The rest of the arguments are values to be converted.

For example

>> printf("e = %g, pi = %g\n", e, pi);
   e = 2.71828, pi = 3.14159

If f is a file, then it has a printf attribute function. For example,

>> f.printf("e = %g, pi = %g\n", e, pi);
will write the string e = 2.71828, pi = 3.14159 to the file. Alternatively, we can also use the built-in function fprintf to write a formated string to a file
>> fprintf(f, "e = %g, pi = %g\n", e, pi);



oz 2009-12-22