C의 스프린트프()
통사론:
int sprintf(char *str, const char *string,...);
반품:
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는 문자열 인쇄를 나타냅니다. 콘솔에 인쇄하는 대신 sprintf에 지정된 char 버퍼에 출력을 저장합니다.
씨
// 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;> }> |
산출
Sum of 10 and 20 is 30
시간 복잡도: O(n) , 여기서 n은 버퍼에 저장되는 요소의 수입니다.
보조 공간: O(n) , 여기서 n은 버퍼에 저장되는 요소의 수입니다.