📘 Lesson  ·  Lesson 67

String Without string.h

String Without string.h

Working Without string.h

💡 Note

You can find string length, copy and reverse manually without library functions like strlen or strcpy.

String Length

C
#include <stdio.h>
int main() {
    char str[] = "Hello";
    int len = 0;
    while (str[len] != '\0') len++;   // count until null
    printf("Length: %d", len);   // 5
    return 0;
}
Output:
Length: 5

Reverse

C
char str[] = "abc", rev[10];
int len = 0;
while (str[len]) len++;
for (int i = 0; i < len; i++)
    rev[i] = str[len-1-i];
rev[len] = '\0';
printf("%s", rev);   // cba
Output:
cba

Summary

  • A C string ends with the null character \0 — loop until you reach it.
  • Reverse by copying characters from the end to a new array.

string.h के बिना काम

💡 Note

आप string की length, copy और reverse manually कर सकते हैं बिना strlen या strcpy जैसी library functions के।

String Length

C
#include <stdio.h>
int main() {
    char str[] = "Hello";
    int len = 0;
    while (str[len] != '\0') len++;   // null तक count
    printf("Length: %d", len);   // 5
    return 0;
}
Output:
Length: 5

Reverse

C
char str[] = "abc", rev[10];
int len = 0;
while (str[len]) len++;
for (int i = 0; i < len; i++)
    rev[i] = str[len-1-i];
rev[len] = '\0';
printf("%s", rev);   // cba
Output:
cba

सारांश

  • C string null character \0 पर खत्म होती है — उस तक loop करें।
  • Reverse को characters अंत से नई array में copy करें।
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n