LED PANEL

Google It, You'll Get It.

Saturday, February 5, 2011

String starting with 'b; in a given series of strings


header file stdio.h
header file string.h


main()

{
int i;
const int stringLimit = 5;

char s[stringLimit][50]; //row and column

printf("enter the strings \n");
for(i=0;i gets(s[i]);

/*for(i=0;i // if(str[i][0]=='b';
printf("str %s \n",s[i]);*/

printf("\n strings Starting wIth letter 'b' \n");
for(i=0;i if(s[i][0]=='b')
printf("word %d : %s \n",i+1,s[i]);

}

Pig - Latin phrase from English language phrase ( Converting words into pig latin )

input : computer
output: omputercay ( omputer + c + ay )
-----------------------------------------------
input : jump
output: umpjay ( ump + j + ay )
-----------------------------------------------

//header file stdio.h
//header file string.h

main()

{
int i=0,wordcount=0;
char word[50];
char reorder[50];
char frst;

printf("enter the word : ");
gets(word);


frst = word[0];

for( i=0 ; word[i+1] != 0 ; i++)
{
reorder[i]=word[i+1];
}

reorder[i]=frst;
reorder[i+1]='a';
reorder[i+2]='y';
reorder[i+3]='\0';


printf("the pigLatin word is %s \n",reorder);


}

Monday, January 31, 2011

Scan and delete a desired a word from a sentence



#include

main()
{
int i=0;
int length = 0;
int word = 1;
int remove=0;
int tempw=1;

//read the string
char strng[50];
printf("enter the string : ");
gets(strng);
printf("Saved String : ");
puts(strng);
//printf("Initial values : Length %d, word %d, wotd numb %d, i %d. \n",length, word, wn, i);

//calculate the length
while(strng[i]!='\0')
{
length++;
i++;
}
printf("String Length : %d \n",length);

// calculate the no of words
i=0;
word=1;
while(i {
if(strng[i]==' ')
word++;
i++;
}
printf("nO. of Words : %d \n",word);

//askng for the word to delete
printf("Enter the word number you need to delete : ",word);
scanf("%d",&remove);

//scaning for that word
for(i=0;i { if(strng[i]==' ')
tempw++; // 2nd word count
if(tempw==remove)
printf("%c",strng[i]);
}
}

Scan a Character win a string and replace it if its available

#include<'stdio.h'>

main()
{
char name[20];
//input
printf("enter the name : ");
scanf("%s",&name);

//out
printf("**%s** \n",name);

//count
int count=1;
for(count=0;name[count]!='\0';count++);
printf("count %d \n",count);

flushall();

/*
char n;
printf("enter the letter : ");
scanf("%c",&n);

int ncount = 0, i =0;
for(i=0;i<=count;i++)
if(name[i]==n)
ncount++;

printf("ncount %d \n",ncount);*/


//scanng lettr
char n;
printf("enter the letter (scan) : ");
scanf("%c",&n);
flushall();

//replacing letter
char m;
printf("enter the letter (replace): ");
scanf("%c",&m);

int i =0;
for(i=0;i<=count;i++)
if(name[i]==n)
name[i]=m;

printf("%s",name);




}

Palindrome Word checker

What are palindrome Words? http://rinkworks.com/words/palindromes.shtml



#include
main()
{
char word[10], test='T';
int l = 0, i = 0; // l=length

printf("enetr the word : ");
scanf("%s",&word);

//length checkng
for (i=0;word[i]!='\0';i++)
{
l++; // length of the word
}
printf("wrd count %d \n",l);

//check
/* while(i!=l)
{
while( word[i]==word[l-i] )
{
printf("match");
i++;
//j--;
}

}
*/
//checkz
l=i-1;
for(i=0;i<(l/2);i++)
{
if(word[i]!=word[l-i])
test='F';
}

if(test=='T')
printf("Yes");
else
printf("No");
}

String Counter in Simple C

#include<'stdio.h'>
main()
{
char fname[10];
char lname[10];

int fc=0,lc=0,i=0;

printf("----in----\n");
scanf("%s",&fname);
scanf("%s",&lname);

printf("----out----\n");
printf("%s \n",fname);
printf("%s \n",lname);


i=0;
while(fname[i] != '\0')
{
fc++;
i++;
}

i=0;
while(lname[i] != '\0')
{
lc++;
i++;
}



printf("\nfrst : %d \n",fc);
printf("lst : %d \n",lc);
}

Using %s for strings + char array

#include<'stdio.h'>
main()
{
char fname[10];
char lname[10];

printf("----in----\n");
scanf("%s",&fname);
scanf("%s",&lname);

printf("----out----\n");
printf("%s \n",fname);
printf("%s \n",lname);
}