Syntaxis:
hoofdmethode java
int sprintf(char *str, const char *string,...);>
Opbrengst:
If successful, it returns the total number of characters written excluding null-character appended in the string, in case of failure a negative number is returned .>
sprintf staat voor Stringprint. In plaats van af te drukken op de console, slaat het de uitvoer op in de char-buffer die is gespecificeerd in sprintf.
C
// Example program to demonstrate sprintf()> #include> int> main()> {> >char> buffer[50];> >int> a = 10, b = 20, c;> >c = a + b;> >sprintf>(buffer,>'Sum of %d and %d is %d'>, a, b, c);> >// The string 'sum of 10 and 20 is 30' is stored> >// into buffer instead of printing on stdout> >printf>(>'%s'>, buffer);> >return> 0;> }> |
>
>Uitvoer
Sum of 10 and 20 is 30>
Tijdcomplexiteit: O(n) , waarbij n het aantal elementen is dat in de buffer wordt opgeslagen.
Hulpruimte: O(n) , waarbij n het aantal elementen is dat in de buffer wordt opgeslagen.