String Programs in C Programming
String Programs in C Programming
Introduction to String Programs in C Programming
String programs in C programming help you understand how to manipulate and process text data using logic and string functions.
Practicing string programs in C programming improves problem-solving skills and strengthens your understanding of strings.
Program 1: Find Length of String Without strlen()
int main() {
char str[] = “Hello”;
int i = 0;
while(str[i] != ‘\0’) {
i++;
}
printf(“Length = %d”, i);
return 0;
}
Program 2: Reverse a String
int main() {
char str[] = “Hello”;
int i, length = 0;
char temp;
while(str[length] != ‘\0’) {
length++;
}
for(i = 0; i < length / 2; i++) {
temp = str[i];
str[i] = str[length – i – 1];
str[length – i – 1] = temp;
}
printf(“Reversed string = %s”, str);
return 0;
}
Program 3: Check Palindrome String
int main() {
char str[] = “madam”;
int i, length = 0, flag = 1;
while(str[length] != ‘\0’) {
length++;
}
for(i = 0; i < length / 2; i++) {
if(str[i] != str[length – i – 1]) {
flag = 0;
break;
}
}
if(flag)
printf(“Palindrome”);
else
printf(“Not Palindrome”);
return 0;
}
Program 4: Copy String Without strcpy()
int main() {
char str1[] = “C Programming”;
char str2[50];
int i = 0;
while(str1[i] != ‘\0’) {
str2[i] = str1[i];
i++;
}
str2[i] = ‘\0’;
printf(“Copied string = %s”, str2);
return 0;
}
Program 5: Concatenate Two Strings Without strcat()
int main() {
char str1[50] = “Hello “;
char str2[] = “World”;
int i = 0, j = 0;
while(str1[i] != ‘\0’) {
i++;
}
while(str2[j] != ‘\0’) {
str1[i] = str2[j];
i++;
j++;
}
str1[i] = ‘\0’;
printf(“Concatenated string = %s”, str1);
return 0;
}
Program 6: Count Vowels and Consonants
int main() {
char str[] = “Hello World”;
int i, vowels = 0, consonants = 0;
for(i = 0; str[i] != ‘\0’; i++) {
if(str[i]==‘a’||str[i]==‘e’||str[i]==‘i’||str[i]==‘o’||str[i]==‘u’||
str[i]==‘A’||str[i]==‘E’||str[i]==‘I’||str[i]==‘O’||str[i]==‘U’) {
vowels++;
}
else if((str[i] >= ‘a’ && str[i] <= ‘z’) || (str[i] >= ‘A’ && str[i] <= ‘Z’)) {
consonants++;
}
}
printf(“Vowels = %d\n”, vowels);
printf(“Consonants = %d”, consonants);
return 0;
}
Why String Programs are Important
Key Benefits
- Improve logical thinking
- Strengthen understanding of strings
- Useful in interviews and exams
- Help in real-world text processing
Common Practice Areas
Important Topics
- String reversal
- Palindrome check
- String comparison
- Character counting
Start Learning C Programming
Practice these string programs to master string handling in C programming.
Summary
String programs in C programming help in understanding how to manipulate text data. They are essential for building strong programming logic.
FAQs
What are string programs in C programming?
They are programs that perform operations on strings.
Why practice string programs?
To improve logic and coding skills.
What is palindrome string?
A string that reads same forward and backward.
Can we perform string operations without functions?
Yes, using loops and conditions.



