UdaanPath Logo UdaanPath

📖 Chapters

Data Structures and Algorithms in C  (DSA)

Data Structures and Algorithms in C (DSA)

Category: IT Fundamentals & Programming

This course is designed to help learners master the core concepts of Data Structures and Algorithms (DSA) using the C programming language. Starting from the basics and advancing to complex topics like graphs, dynamic programming, and memory optimization, this course …

Strings: Manipulation & Inbuilt Functions

📘 Strings – Manipulation & Inbuilt Functions

A string in C is a sequence of characters stored in an array of type char, and it is terminated by a special character '\0' (null character). Unlike other languages, strings in C are not a built-in data type — they are handled as arrays.

🔤 Declaring and Initializing Strings

char name[10];                   // Declaration
char greet[6] = {'H','e','l','l','o','\0'};  // Manual initialization
char str[] = "Hello";            // Automatic null-termination
  

📥 Input and Output for Strings

// Using scanf and gets
char name[50];
scanf("%s", name);       // Stops at space
// gets(name);           // (Unsafe: use fgets instead)

// Using fgets
fgets(name, sizeof(name), stdin); // Safe input
  

📌 Common String Functions (string.h)

  • strlen(str) – Returns the length of the string
  • strcpy(dest, src) – Copies one string into another
  • strcat(dest, src) – Concatenates two strings
  • strcmp(str1, str2) – Compares two strings (returns 0 if equal)
  • strchr(str, ch) – Returns pointer to first occurrence of ch
  • strstr(haystack, needle) – Returns pointer to substring

🧪 Example Program

#include <stdio.h>
#include <string.h>

int main() {
    char str1[20] = "Udaan";
    char str2[20] = "Path";
    strcat(str1, str2);  // str1 becomes "UdaanPath"
    printf("Combined: %s\n", str1);
    return 0;
}
  

📊 Real-Life Use Case – UdaanPath

Suppose you're storing user names in an educational app like UdaanPath. Each user’s name and email can be stored using strings and validated using strlen, strcmp, etc.

⚙️ Operations on Strings

  • Traversing using loops
  • Reversing a string
  • Counting vowels, consonants, digits
  • Palindrome check
  • Character frequency

🧠 String vs Character Array

  • A string always ends with '\0'
  • Character arrays may not necessarily be null-terminated
  • Use string.h functions only with null-terminated strings

📚 Practice Tasks

  • Write a program to reverse a string
  • Count the number of vowels and consonants
  • Check if a string is a palindrome
  • Compare two strings entered by user

✅ Summary

  • Strings are arrays of characters ending with '\0'
  • Use string.h for common operations like copy, compare, and length
  • Be cautious of buffer overflow and always allocate extra space for '\0'

📤 Coming Next

In the next chapter, we’ll explore Structures and Unions — composite data types used for storing grouped and flexible data in C.

ECHO Education Point  📚🎒

ECHO Education Point 📚🎒

ECHO Education Point proudly presents its Full Stack Development program 💻 – designed to launch your career in tech!

  • 🚀 Master both Front-End and Back-End technologies
  • 🧪 Includes 11 Mock Tests, 35 Mini Projects & 3 Website Builds
  • 🎯 Special training for job interviews & placement preparation

📍 Location: D-Mart Road, Meghdoot Nagar, Mandsaur
📞 Contact: 8269399715

Start your coding journey with expert instructor Vijay Jain (B.C.A., M.Sc., M.C.A.)
10 Days Free Demo Classes – Limited seats available!

#ECHO #FullStackDevelopment #MandsaurCoding