C Program For String
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
// String Related Programming in C
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i;
printf("Enter a String...");
gets(str);
//scanf("%s",str);
i=0;
//printf("%s",str);
while(str[i]!='\0')
{
printf("%c",str[i]);
i++;
}
return 0;
}Program 2
// Count length of String in C
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i=0;
printf("Enter a String...");
gets(str);
// while(str[i]!='\0')
// i++;
i=strlen(str);
printf("Length of String : %d",i);
return 0;
}Program 3
// print string from lower case to upper case in C
// print string from upper case to lower case in C
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i=0;
printf("Enter a String...");
gets(str);
//puts(strupr(str));
puts(strlwr(str));
// while(str[i]!='\0')
// {
// if(str[i]!=' ')
// printf("%c",str[i]+32);
// else
// printf("%c",str[i]);
// i++;
// }
return 0;
}Program 4
// String reverse in C
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[100];
int i;
printf("Enter a String:");
gets(str);
puts(strrev(str));
puts(str);
//i=strlen(str);
// printf("Length of string %d",i);
// i=i-1;
// while(i>=0)
// {
// printf("%c",str[i]);
// i--;
// }
return 0;
}
Did you like this article? If Yes, please give DataFlair 5 Stars on Google

