私はCS50のpset4に取り組んでおり、recover.cのどこにsprintfを使用するのが本当に混乱しています.CS50の問題です。sprintfとprintfを正確に何でどこで使うべきかを知りたいです。Cのsprintfとprintfの違いは何ですか?
-5
A
答えて
0
sprintf
文字列をフォーマットし、最初の引数で指定された文字配列に書き込みます(十分なスペースがあると仮定します)。 printf
は文字列をフォーマットし、stdout
に書き込みます。
例:あなたはsprintf
でこれを行うことができます。
char buffer[100];
sprintf(buffer, "My name is %s and I am %d years old", "John Doe", 25);
// buffer now contains "My name is John Doe and I am 25 years old"
あなたが標準出力ストリームにフォーマットされた文字列を書き込みたい場合は、あなたが最初の引数としてstdout
でprintf
(またはfprintf
を使用する必要があります):
printf("My name is %s and I am %d years old", "John Doe", 25);
// the text "My name is John Doe and I am 25 years old" gets printed to the stdout stream
+0
うわー、本当に助けてくれました。 – kartikey21
+1
実際それはしませんでした。基本的な研究を行う方法を学ぶことができませんでした。 Tsk。 –
関連する問題
- 1. `printf`の%* c%* cとは何ですか?
- 2. printf/sprintf madness(spontanous concatenation)
- 3. はsprintfとC
- 4. CとC++での "const"の違いは何ですか?
- 5. printfの署名とは何ですか?
- 6. jtype(JNIの)とC/C++のタイプの違いは何ですか?
- 7. C/C++のrand、urandとirandの違いは何ですか?
- 8. 「Cシステムコール」と「Cライブラリルーチン」の違いは何ですか?
- 9. c-findとc-get DIMSEの違いは何ですか?
- 10. "C#editor"と "C#editor with encoding"の違いは何ですか?
- 11. printfのlcとc/lsとsの違い
- 12. C++の "new"と "malloc"と "calloc"の違いは何ですか?
- 13. C++でのマルチスレッドのjoin()とdetach()の違いは何ですか?
- 14. C++&arrayとarrayの使い方の違いは何ですか?
- 15. .NET doubleとpython floatの違いは何ですか? C#ので
- 16. Cの中のpopen()とsystem()の違いは何ですか
- 17. Obj-Cのself.xxxとcalling xxxの違いは何ですか?
- 18. C#の内部クラスとパブリッククラスの違いは何ですか?
- 19. C#のArrayListとHashtableの違いは何ですか?
- 20. C#のオブジェクトとクラスの違いは何ですか?
- 21. riscvのisa-simulatorとC++シミュレータの違いは何ですか?
- 22. Objective-CのinstancesRespondToSelectorとrespondsToSelectorの違いは何ですか?
- 23. JavaとC++のイテレータの違いは何ですか?
- 24. Objective-Cの "_"と "__"の違いは何ですか?
- 25. C#のFileとFileInfoの違いは何ですか?
- 26. objective-cの[myString length]とmyString.lengthの違いは何ですか?
- 27. Turbo C++のトレース(F7)とステップオーバー(F8)の違いは何ですか?
- 28. c socket()関数の型とプロトコルの違いは何ですか?
- 29. C#のPingクラスとWebClientクラスの違いは何ですか?
- 30. Cのポインタとグローバル変数の違いは何ですか?
マニュアルページをお読みください。 –
まあ、最初の引数の型が異なります。 – wildplasser
Googleはあなたの友人です。 – Stef