Apr
21
Mar
30
//concat strings
#include<stdio.h>
void main(){
char st1[50],st2[50],st3[100];
int i,j;
printf(“Enter First string: “);
gets(st1);
printf(“Enter First string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++){
st3[i]=st1[i];
}
j=i;
for(i=0;st2[i]!=’\0′;i++){
st3[j]=st2[i];
j++;
}
//puts(st3);
}
Mar
30
//reverse strings
#include<stdio.h>
void main(){
char st1[100];
int i,j;
printf(“Enter First string: “);
gets(st1);
for(i=0;st1[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
printf(“%c”,st1[j]);
}
}
Mar
30
//compare strings
#include<stdio.h>
void main(){
char st1[100],st2[100];
char ch;
int i,j,k,flg=0;
printf(“Enter First string: “);
gets(st1);
printf(“Enter Second string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++);// to get the length of st1
for(j=0;st2[j]!=’\0′;j++);// to get the length of st2
if(i==j){
for(k=0;k<i;k++){
if(st1[k]!=st2[k]){
flg=1;
break;
}
}
if(flg==0)
printf(“Both Strings are same”);
else
printf(“Both Strings are not same”);
}
else{
printf(“Both Strings are not same”);
}
}
Mar
30
/*
HELLO
HELL
HEL
HE
H
*/
#include<stdio.h>
void main(){
char st[100];
char ch;
int i,j,k;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
for(k=0;k<=j;k++){
printf(“%c”,st[k]);
}
printf(“\n”);
}
}
Mar
30
/*
HHHHH
EEEE
LLL
LL
O
*/
#include<stdio.h>
void main(){
char st[100];
char ch;
int i,j,k;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++);
for(j=0;st[j]!=’\0′;j++){
for(k=i-1;k>=j;k–){
printf(“%c”,st[j]);
}
printf(“\n”);
}
}
Mar
29
#include<stdio.h>
void main(){
char st[100];
int i,j;
int len=0;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++){
len++;
}
for(i=len-1;i>=0;i–){
for(j=0;j<=i;j++){
printf(“%c\t”,st[j]);
}
printf(“\n”);
}
}
Mar
29
#include<stdio.h>
void main(){
char st[100];
int i,j;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++){
for(j=0;j<=i;j++){
printf(“%c\t”,st[i]);
}
printf(“\n”);
}
}
Mar
29
#include<stdio.h>
void main(){
char st[100];
int i,j;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++){
for(j=0;j<=i;j++){
printf(“%c\t”,st[j]);
}
printf(“\n”);
}
}
Mar
25
//get length of string in C
#include<stdio.h>
void main(){
char name[100];
int i;
printf(“Enter Your name: “);
//scanf(“%s”,name);
gets(name);
printf(“%d\n”,sizeof(name));
printf(“Your name is: %s\n”,name);
for(i=0;name[i]!=’\0′;i++);
printf(“Length of string: %d”,i);
}
Mar
25
//string character in each line
#include<stdio.h>
void main(){
char name[100];
int i;
printf(“Enter Your Name: “);
//scanf(“%s”,name);
gets(name);
//for(i=0;i<100;i++)
for(i=0;name[i]!=’\0′;i++)
printf(“%c\n”,name[i]);
}
Mar
25
#include<stdio.h>
 void main(){
 char name[100];
 printf(“Enter Your Name: “);
 //scanf(“%s”,name);
 gets(name);
 printf(“Entered Name is: %s”,name);
 }
Mar
25
//string initialization
#include<stdio.h>
 #include<stdlib.h>
 void main(){
 //char nm[40]=”Hello”;
 //printf(“%d\n”,sizeof(nm));
 //char nm[]=”Hello”;
 //printf(“%d\n”,sizeof(nm));
 //char nm[]={‘H’,’e’,’l’,’l’,’o’,’\0′};
 //printf(“%d\n”,sizeof(nm));
 char nm[40]={‘H’,’e’,’l’,’l’,’o’};
 printf(“%d\n”,sizeof(nm));
 //nm[40]=”Hello”;
 //nm[3]=’A’;
 printf(“%s”,nm);
 }