Playing with Strings in C

These program codes help us to play with strings in C.
This Program code inputs a string and displays the characters until a single character.



#include<string.h>
#include<stdio.h>
int main()
{
char o[50],c,t;
int i,j;
printf("Enter the string: ");
gets(o);
printf("Enter the terminating character: ");
scanf("%c",&t);
j = strlen(o);
for(i=0;i<j;i++)
{
if( o[i] == t )
{
break;
}
else
{
printf("%c",o[i]);
}
}
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub
This program code accepts a string and displays it excepting certain characters.
#include<string.h>
#include<stdio.h>
int main()
{
char o[50],t;
printf("Enter the string: ");
gets(o);
printf("Enter the character to except: ");
scanf("%c",&t);
int i,j;
j = strlen(o);
for(i=0;i<j;i++)
{
if(o[i] == t )
{
continue;
}
else
{
printf("%c",o[i]);
}
}
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments