C_64 Strings in C- part 3 | printf and puts function in C
Summary
TLDRThe video script discusses various programming concepts related to strings in C. It covers how to read a string, the use of functions like 'scanf' and 'gets', and their advantages. The script also explains the syntax and function of 'printf' and 'puts' for displaying strings on the screen. It delves into the implementation of these functions, how to handle string input, and the importance of proper formatting. The video aims to educate viewers on the intricacies of string handling in C programming, providing a comprehensive guide for beginners.
Takeaways
- 😀 The video discusses strings in C programming, focusing on how to read, use, and manipulate them.
- 🔍 It covers the use of 'scanf' and 'gets' functions to read strings at runtime, along with their advantages when used together.
- 📝 The 'printf' and 'puts' functions are introduced for printing strings on the screen, with 'puts' being a simpler alternative to 'printf' for single characters.
- 🔑 The syntax and use of 'printf' function are explained, including formatting specifiers and how to declare a string with a size of 30 characters.
- 👉 The importance of using '%s' to read a string and '%c' to read individual characters is highlighted.
- 📚 It explains how to use loops and address operators to print the entire string, including the null character at the end.
- 🎯 The concept of memory allocation for strings is introduced, showing how a string of 30 characters is allocated with a starting address.
- 📌 The video clarifies the difference between 'printf' and 'puts' functions, especially how 'puts' automatically adds a newline at the end of the string.
- 👓 It discusses the use of predefined functions like 'strlen', 'strcat', 'string reverse', and other functions for string manipulation.
- 📝 The video also touches on the implementation of 'printf' and 'puts' functions, explaining that they are pre-declared in the header files.
- 🔄 The script ends with a teaser for the next video, which will continue exploring strings and standard functions like 'strlen' and 'strchr'.
Q & A
What is the main topic discussed in the video?
-The main topic discussed in the video is learning programming with a focus on strings in the C programming language, including how to read, use, and manipulate strings.
What are some of the functions discussed in the video for handling strings in C?
-The video discusses functions like `printf`, `puts`, and `scanf` for handling strings in C, including how to print a string on the screen and how to read user input.
How does the video explain the use of `scanf` for reading strings?
-The video explains that `scanf` can be used to read strings by specifying the format specifier `%s` and providing the name of the string variable where the input will be stored.
What is the purpose of the `printf` function in the context of the video?
-The `printf` function is used to print formatted output to the screen, such as displaying a string or a message with specific formatting.
How does the video describe the process of printing a specific character from a string?
-The video describes that to print a specific character from a string, you can use a loop to iterate through the string and print each character individually using the `printf` function.
What is the difference between `scanf` and `gets` as mentioned in the video?
-The video mentions that `gets` is a function that was used to read strings, but it is not recommended due to security issues. Instead, `scanf` with a format specifier is suggested for safer string input.
How is the `puts` function used in the video to handle strings?
-The `puts` function is used to print a string followed by a newline character to the screen. It is a simpler alternative to `printf` when only a string needs to be displayed.
What is the significance of the format specifier `%s` in the context of string functions?
-The format specifier `%s` is significant as it tells the `scanf` or `printf` function to expect or display a string, respectively.
How does the video explain the concept of string pointers in C?
-The video explains that a string pointer in C points to the first character of a string. It discusses how to use pointers to access and manipulate strings, such as printing a string using a pointer.
What is the importance of null termination in strings as discussed in the video?
-The video emphasizes the importance of null termination in strings, which is the use of the null character (`'\0'`) to mark the end of the string. This is crucial for functions like `printf` to know where the string ends.
How does the video address the issue of buffer overflow when reading strings?
-The video addresses buffer overflow by discussing the use of `scanf` with format specifiers to limit the number of characters read, thus preventing the risk of overwriting memory beyond the string's allocated space.
Outlines
📚 Understanding Strings in C Programming
This paragraph provides an overview of the discussion on strings in C programming. It covers the functions `scanf` and `gets` for reading strings, and introduces the `printf` and `puts` functions for printing strings. It explains how `puts` can be used to print a single character in a loop to display an entire string and discusses the syntax and use cases for `printf` to print strings, including formatting options and field width specifications.
🖨️ Using the `puts` Function
This section delves into the `puts` function, explaining its simplicity compared to `printf`. It emphasizes that `puts` automatically adds a newline at the end of the string. The paragraph highlights the header file `stdio.h` where `puts` is declared and compares its behavior with `printf` when both are used in the same program. The key point is that `puts` ensures each string is printed on a new line, unlike `printf`, which continues on the same line unless explicitly instructed otherwise.
🔍 Exploring String Functions in C
This final paragraph introduces the upcoming video topics related to string functions in C. It mentions functions like `strlen` for finding string length, `strcat` for concatenation, and reversing strings. The paragraph promises practical examples and usage of these standard string functions, providing a teaser for viewers to tune in for the next video where these concepts will be demonstrated.
Mindmap
Keywords
💡Learning Programming
💡Strings in C
💡Reading a String
💡Pointers
💡Printf Function
💡Format Specifiers
💡Loops
💡Memory Allocation
💡String Length
💡Standard Functions
💡Predefined Functions
Highlights
Introduction to learning programming with a focus on strings in C.
Explanation of how to read a string and how to use input functions.
Discussion on using 'scanf' and 'gets' functions for input.
Advantages of using both 'scanf' and 'gets' functions.
Introduction to 'printf' and 'putchar' functions for output.
How to use 'printf' for formatted output and printing a string.
Using 'putchar' to print a single character within a loop.
Explanation of string declaration and its size.
How to take user input for a string using format specifiers.
Details on string storage, memory allocation, and character limits.
Demonstration of using pointers to access and manipulate strings.
How to print a specific character from a string using its index.
Using 'printf' with format specifiers to print a formatted string.
Explanation of string termination with a null character.
Difference between 'printf' and 'puts' functions for printing strings.
How to use predefined functions like 'strlen', 'strcat', 'strrev', etc.
Practical examples of string manipulation in C programming.
Conclusion and预告 of the next video on strings and standard functions.
Transcripts
सो इन द सीरीज ऑफ़ लर्निंग प्रोग्रामिंग
इन सी वी आर डिस्कसिंग स्ट्रिंग्स इन सी
इन द प्रीवियस वीडियो वी हैव डिसकस्ड हाउ
टू रीड अ स्ट्रिंग और हाउ टू यू कैन से
इनिला इज अ स्ट्रिंग एट रन टाइम यूजिंग
स्कैन एफ एंड गेट एस राइट वी हैव डिस्कस
एडवांटेज एक ऑफ बोथ स्कैन एफ एंड गेट एस
फंक्शन इन दिस वीडियो वी विल टॉक अबाउट
प्रिंट एफ एंड पटस फंक्शन मींस दीज टू
फंक्शंस आर यूज्ड टू प्रिंट अ स्ट्रिंग ऑन
द स्क्रीन पुट कैर कैन आल्सो बी यूज़ बट
पुट क इज बेसिकली यूज्ड टू प्रिंट अ सिंगल
कैरेक्टर सो यू जस्ट पुट दैट फंक्शन इनटू
अ फर लूप एंड यू कैन प्रिंट द एनटायर हा
हाउ वी विल यूज प्रिंट एफ एंड पुट एस
फंक्शन वी विल यूज द सिंटेक्स एंड ऑल द
पॉइंट्स अबाउट दीज टू फंक्शंस राइट सो
फर्स्ट इज व्हाट प्रिंट एफ सिंपल सिंटेक्स
इज व्ट आई थिंक एवरी बडी नो वी राइट जस्ट
फॉर्मेट
स्पेसिफिसिटी नेम ऑफ द स्ट्रिंग सपोज हेयर
आई एम डिक्लेयर अ स्ट्रिंग केर नेम 30
साइज इज 30 राइट एंड आई एम आस्किंग फ्रॉम
द यूजर टू एंटर द स्ट्रिंग एंड दैट आई एम
गोइंग टू टेक
यूजिंग
स्कन परसेंटेज एस एंड नेम नो नीड टू राइट
डाउन एनी फोर लूप और एड्रेस ऑफ ऑपरेटर यर
राइट सपोज यूजर हैज एंटर्ड स्ट्रिंग एंड
नाउ आई वाट टू प्रिंट दैट स्ट्रिंग सो
जस्ट प्रिंट दैट स्ट्रिंग परसेंटेज एस एंड
नेम ऑफ द स्ट्रिंग लाइक नेम दैट एक् एस अ
पॉइंटर टू द स्ट्रिंग सो हेयर लाइक दिस
दिस लोकेशन हैज बीन एलोकेटेड टू दिस
स्ट्रिंग लाइक अप टू 30 इंडेक्स वुड बी 0
टू अप टू 29 30 बाइट्स व हैव बीन एलोकेटेड
सपोज एड्रेस ज 2000 फर्स्ट बाइट एड्रेस
2000 देन न 2001 2002 लाइक दिस अप टू
2029 राइट एंड सपोज आई हैव एंटर्ड समथिंग
लाइक दिस इट इज आस्किंग लाइक व्हेन यू आर
गोइंग टू एंटर नेम तो मे बी य बिफोर द
स्कन यू कैन आल्सो राइट न मोर प्रिंट एफ
एंटर नेम राइट एंड इट इज आस्किंग स सपोज
एंटर
नेम हेयर सपोज आई एम राइटिंग बिफोर दिस
स्कन एफ आई एम राइटिंग वन मोर लाइन प्रिंट
एफ एंटर नेम आई वाट दिस शुड बी प्रिंटेड
ऑन द स्क्रीन फर्स्ट सो आई एम एंटरिंग
नेम
जयंती राइट सो इट वुड बी स्टोर्ड
हेयर
एंड एट लास्ट सपोज आईम एंटरिंग ओनली दिस
एंड आफ्टर दिस यू प्रेस एंटर सो एट
लास्ट स्लश सॉरी नल वड बी एडेड टू इंडिकेट
दैट दिस इ एंड ऑफ स्ट्रिंग सो दिस एयर इ
वट कैरेक्टर एरे एंड दिस इ व्ट स्ट्रिंग
स्ट्रिंग इ लवेज एंडिंग विद अ नल कैरेक्टर
एंड हेयर वी हैव सम गार्बेज वैल्यू सो
जस्ट प्रिंट इट नेम मींस दिस दिस दिस शुड
बी प्रिंटेड इन
नेम नेम ऑफ़ दिस कैरेक्टर एरे इज़ नेम और
यू कैन से स्ट्रिंग इज़ नेम एंड दिस इज़
कंटेनिंग 2000 द एड्रेस सो इट इज़ पॉइंट द
फर्स्ट कैरेक्टर ऑफ़ द स्ट्रिंग राइट सो
जयंती वुड बी प्रिंटेड ऑन द स्क्रीन राइट
नाउ सी व्हाट यू कैन डू इन दिस प्रिंटर इफ
यू वांट टू प्रिंट स्पेसिफाइड कैरेक्टर
सपोज आई डोंट वांट टू प्रिंट ऑल द
कैरेक्टर आई जस्ट वांट टू प्रिंट फाइव
कैरेक्टर्स ऑफ़ माय नेम सो सो इफ यू राइट
समथिंग लाइक
दिस फ एंड देन
s5 देन s सो इट विल प्रिंट व्हाट j एवा ए
ए ओनली द फर्स्ट फाइव कैरेक्टर ऑफ माय नेम
बिकॉज आई हैव स्पेसिफाइड दिस एंड इफ यू
राइट समथिंग लाइक दिस प्रिंट ए परसेंटेज
सपोज आई एम राइटिंग
अ 10
फ एंड देन एस फॉर्मेट
स्पेसिफाइड केस व्ट वड बी द आउटपुट दिस
10 दिस 10 वड बी द फिल्ड विथ राइट लाइक
टूथ 4 5 6 7 8 ना 10 दिस इ द फीड विथ एंड
यर ओनली फाइ कैरेक्टर्स ऑफ माय नेम ड बी
प्रिंटेड एट वड बी ट राइट शिफ्टेड सो हेयर
प्रिंटेड ज वा ए
ए दिस आउटपुट य विल गेट आईन यू विल नॉट
गेट दिस अंडरस्कोर हेयर आईम जस्ट यू नो
हेयर इट जस्ट मेक यू अंडरस्टैंड दैट हेयर
वी हैव फिड विड सो देर आर स्पेसेस सो
समथिंग लाइक दिस दिस वुड बी प्रिंटेड हेयर
यू विल गेट सम स्पेस राइट बिकॉज यू आर
प्रोवाइड फीड विड्थ सो दैट इज आई गेस ल
अबाउट प्रिंट एफ हाउ टू यूज प्रिंट एफ टू
प्रिंट अ स्ट्रिंग एंड हाउ टू यूज नाउ पुट
एस इ इफ यू हियर राइट पुट s इट इज़ वेरी
सिंपल टू यूज़ नो फॉर्मेट स्पेसिफाई टू बी
यूज्ड ओनली राइट द फंक्शन पुट s एंड द नेम
ऑफ़ द
स्ट्रिंग दैट इज़ नेम सी पुट दिस इज़
ऑलरेडी दिस इज यू कैन से प्री डिफाइंड
फंक्शन लाइक प्रिंट एफ प्रिंट एफ इज
ऑलरेडी इ प्री डिफाइंड फंक्शन व्हिच इज
डिक्लेयर्ड इन व्हिच हेडर फाइल एडीओ ए
राइट
दैट्ची नर प्रोग्राम राइट सो पुस इज आल्सो
डिक्लेयर्ड इन च हेडर फाइल एसटीडी ड
ए राइट बिकॉज ओबवियसली व्हेन यू आर
राइटिंग दिस पुस कंपाइलर डोंट नो व्हाट इज
मीनिंग ऑफ दिस पुस व्हाट ही हैज टू डू विद
दिस पुस सो द मीनिंग यू कैन से हैज बीन
डिक्लेयर्ड इन एसटीडी ड ए दिस हेडर
फाइल सो नाउ यूजिंग दिस हेडर फाइल नाउ
कंपाइलर नो लाइक मीनिंग ऑफ दिस पटस इज
पुट एस विल प्रिंट व्हाट एवर इज पास्ड यर
द नेम ऑफ द स्ट्रिंग दैट स्ट्रिंग ऑन द
स्ट्रिंग पुस हैज टू प्रिंट दैट थिंग दैट
इज मीनिंग ऑफ पुस राइट सो नाउ वी विल गेट
द आउटपुट
राइट सो नाउ हेयर ओनली डिफरेंस इज व्हाट
इन दिस पुट एस फंक्शन विल ऑटोमेटिक ऐड अ
न्यू लाइन एट द एंड ऑफ द
स्ट्रिंग व्हाट आई एम सेइंग सी इन दिस केस
दिस आउटपुट यू विल गेट राइट एंड सी इफ बोथ
प्रिंट एफ आर यूजिंग इन सेम प्रोग्राम वी
आर नॉट यूजिंग एनी न्यू लाइन ऑपरेटर हेयर
सो नेक्स्ट आउटपुट यू विल गेट इन द सेम
लाइन मींस हेयर 1 2 3 4
5 फाइव स्पेसेस एंड देन जे एवाई ए ए बिकॉज
वी आर प्रंग फीड विथ फील्ड विथ 10 लाइक
दिस वी विल गेट द आउटपुट राइट बट नाउ पुट
एस सपोज आई एम आई वांट टू यूज टू पटस इन द
सेम प्रोग्राम नाउ राइट सो नाउ व्ट आउटपुट
य विल गेट नेम इ जयंती सो जे ए वाई ए एटी
आई राइट एंड अगेन पुट नेम सो नेम वड नॉट
बी प्रिंटेड इन द सेम लाइन इट वड बी
प्रिंटेड इन द नेक्स्ट लाइन दिस आउटपुट य
विल गेट बिकॉज पुस विल ऑटोमेटिक ड न्यू
लाइन ऑपरेटर मींस इट्स एंड ऑफ द स्ट्रिंग
कर्सर ड ऑटोमेटिक बी इन द नेक्स्ट
लाइन सो नेक्स्ट आट य विल गेट इन द
नेक्स्ट लाइन इफ यू राइट वन मोर पुट एस
नेक्स्ट आउटपुट यू विल गेट इन नेक्स्ट
लाइन
राइट सो हेयर इफ यू आर यूजिंग ऑल द फोर इन
द सेम प्रोग्राम देन व्हाट आउटपुट वी विल
गेट फर्स्ट दिस देन दिस एंड दिस जयंती वुड
आल्सो बी प्रिंटेड इन द सेम लाइन हियर
बिकॉज आफ्टर प्रिंट एफ वी डायरेक्टली
यूजिंग वीी आर डायरेक्टली यूजिंग पुट एस
वी आर नॉट स्पेसिफाइड आफ्टर दिस
वन हेयर सो दिस आउटपुट य विल गेट इन द सेम
लाइन बट
नाउ दिस जयंती वुड बी इन सेम लाइन बट
नेक्स्ट आउटपुट यू विल गेट इन डिफरेंट
लाइन बिकॉज पुस विल ऑटोमेटिक ड न्यू लाइन
आफ्टर प्रिंटिंग द आउटपुट राइट आई होप यू
गट माय पॉइंट राइट सो दिस इज द डिफरेंस
बिटवीन प्रिंट एफ एंड पटस फंक्शन सो आई
थिंक द इंप्लीमेंटेशन ऑफ दिस इ इजी वी
डोंट हैव टू यू नो राइट मच अबाउट दिस वन
सो इट्स इजी टू यूज पोटेस्ट फंक्शन देन
प्रिंटर फंक्शन टू प्रिंट अ स्ट्रिंग राइट
इट इज बेसिकली यू नो
कॉल इट फॉर्मेटेड आउटपुट फंक्शन ट एंड स्न
फॉर्मेटेड इनपुट फंक्शन ट थ डिस्क इन
प्रीवियस वीडियोस ऑफ सी लैंग्वेज एंड वन
मोर थिंग इफ यू राइट प्रिंट समथिंग लाइक
दिस प्रिंट परसेंटेज एस एंड हेर आम
राइटिंग एड्रेस
ऑफ
नेम दिस विल आल्सो प्रिंट वट द स्ट्रिंग
जंती हेर राइट बट हेयर यू राइट समथ लाइक
दिस एड्रेस ऑफ नेम ऑफ टू आई एम प्रोवाइड
इंडेक्स टू एड्रेस ऑफ नेम ऑफ
टू नाउ व्हाट इट विल प्रिंट सी यू आर
प्रोवाइड एड्रेस ऑफ व्ट नेम ऑफ टू मींस
नेम ऑफ टू दिस
वन फ्रॉम दिस
इंडेक्स राइट फ्रॉम सेकंड इंडेक्स सो इट
विल डायरेक्टली स्टार्ट प्रिंटिंग फ्रॉम
दिस इंडेक्स फ्रॉम वा एंड टिल व्हाट इट
विल प्रिंट टिल
इट विल गेट अ नल ऑपरेटर राइट सो व्हाट
आउटपुट य विल गेट हियर वा ए एनटी
आ दिस आउटपुट यू विल गेट राइट बट इफ यू
विल प्रोवाइड समथिंग लाइक दिस ओनली नेम ऑफ
टू नो यू विल नॉट गेट एनी आउटपुट दिस वुड
बी एरर राइट यू कैन ट्राई इट एट योर ओन
फाइन आई थक ट्स इट अबाउट प्रिंट एफ एंड
पुट पटस फंक्शन देर इज नथिंग मच अबाउट दिस
टू फंक्शन फ्रॉम द नेक्स्ट वीडियो वी आर
गोइंग टू सी सम सॉरी प्रोग्राम्स ऑन
स्ट्रिंग एंड वी विल आल्सो बी यूजिंग दैट
स्टैंडर्ड फंक्शंस ऑफ स्ट्रिंग लाइक एसटी
आर एल एन टू फाइंड स्ट्रिंग लेंथ स्ट्रिंग
कन कटने स्ट्रिंग रिवर्स दज काइंड ऑफ़
फंक्शंस एंड प्रोग्राम ऑन दोज अ
प्रेडिफाइंड फंक्शंस राइट वी विल सी
प्रैक्टिकली सो ना आ विल सी यू इन द
नेक्स्ट वीडियो टल देन बाय बाय टेक
केयर
Browse More Related Video
C_63 Strings in C-part 2 | Read a String using scanf and gets function
Strings (Basics of Memory) | Godot GDScript Tutorial | Ep 10.2
Python Tutorial for Beginners 2: Strings - Working with Textual Data
P_06 print() function & String concatenation(using +) in Python | Python Tutorials for Beginners
Strings in Javascript | chai aur #javascript
Optoelectronic devices: Introduction
5.0 / 5 (0 votes)