DMCA.com Protection Status C Programming – Day 6 | Strings in C (Characters & Text Handling) Explained - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

C Programming – Day 6 | Strings in C (Characters & Text Handling) Explained

STRINGS IN C (Characters & Text Handling) 

DAY - 6




✅ We continue your learning progress 🚀


📍 Day-6 — Strings in C (Characters & Text Handling)

Today we will learn:

✅ What is a string?
✅ Declaring & printing strings
✅ Input methods: scanf() vs gets()
✅ String functions
✅ Task + Quiz


✅ 1️⃣ What is a String?

📌 A string is a collection of characters ending with '\0' (NULL character)

Example:

char name[20] = "Jahid";

Memory Layout:

J | a | h | i | d | \0

✅ 2️⃣ Input & Output Strings

✅ Using scanf()

scanf("%s", name); // stops at space

✅ Using gets() — takes full sentence

gets(name);

✅ Using puts() — prints string

puts(name);

Note: gets() is unsafe in real world, but good for learning.


✅ 3️⃣ String Functions (from <string.h>)

FunctionMeaning
strlen(str)Count characters
strcpy(dest, src)Copy string
strcat(str1, str2)Join strings
strcmp(a,b)Compare strings

Example:

#include <string.h> char a[20] = "Hello"; char b[20] = "World"; strcat(a, b); printf("%s", a); // HelloWorld

🧪 Practice Example: Count Vowels

#include <stdio.h> #include <string.h> int main() { char str[50]; int i, count = 0; gets(str); for(i = 0; str[i] != '\0'; i++){ char ch = str[i]; if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'|| ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') count++; } printf("Vowels: %d", count); }

✅ Task-6

Write a program to:

✔ Input your full name
✔ Count and print:

  • Total characters

  • Total vowels

Example Output:

Your Name: Jahid Hasan Total Characters: 11 Total Vowels: 4

📌 Hint: use loop until '\0' reached
📌 Include <string.h> optional

➡ Send your code — I will fix if needed ✅


📝 Quick Quiz — Day-6

Reply like: 1C, 2A, 3B

1️⃣ Strings in C end with:
A) space
B) tab
C) NULL \0

2️⃣ Which function joins two strings?
A) strcat()
B) strcmp()
C) strlen()

3️⃣ Which function counts characters?
A) strcpy()
B) strlen()
C) printf()


✅ Once you finish:

➡ Day-6 Completed
➡ We proceed to Day-7 (Functions in C) 🔥


Send your Task-6 Code and Day-6 Quiz answers when ready! 😄


✅ NEXT - DAY - 7

No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.