Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.
Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Sunday, November 14, 2010

WAP to search a character in a string


/*WAP to search a character in a string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>

main()
{
 char *ptr, str[50];
 int ch;
 // Input of String & character
 printf("\n Enter the String \n");
 gets(str);
 printf("\n Enter the character to search ");
 ch = getchar();
 // Searching the character
 ptr = strchr(str,ch);
 if(ptr == NULL)
  printf("\n Not Found");
 else
  printf("\n The character %c is at the position %d\n",ch,ptr-str);
 getch();
 return 0;
}

Friday, October 8, 2010

WAP to Formatting strings with 't' tab


/*WAP to Formatting strings with 't' tab */
#include<stdio.h>
#include<conio.h>
main( )
{
 printf ( "You\tmust\tbe\tcrazy\nto\thate\tthis\tbook" ) ;
       getch();
}

WAP to Formatting strings with printf( )


/*WAP to Formatting strings with printf( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  firstname1[ ] = "Sandy" ;
 char  surname1[ ] = "Malya" ;
 char  firstname2[ ] = "AjayKumar" ;
 char  surname2[ ] = "Gurubaxani" ;

 printf ( "\n%20s%20s", firstname1, surname1 ) ;
 printf ( "\n%20s%20s", firstname2, surname2 ) ;
       getch();
}

Monday, September 20, 2010

WAP to interchange string3 with string4


/*WAP to interchange string3 with string4*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  *names[ ] = {
      "akshay",
      "parag",
      "raman",
      "srinivas",
      "gopal",
      "rajesh"
   } ;
 char  *temp ;

 printf ( "Original: %s %s", names[2], names[3] ) ;

 temp = names[2] ;
 names[2] = names[3] ;
 names[3] = temp ;

 printf ( "\nNew: %s %s", names[2], names[3] ) ;
}

WAP to Exchange names using 2-D array of characters


/*WAP to Exchange names using 2-D array of characters */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  names[ ][10] = {
      "akshay",
      "parag",
      "raman",
      "srinivas",
      "gopal",
      "rajesh"
        } ;
 int  i ;
 char  t ;

 printf ( "\nOriginal: %s %s", &names[2][0], &names[3][0] ) ;  

 for ( i = 0 ; i <= 9 ; i++ )
 {
  t = names[2][i] ;
  names[2][i] = names[3][i] ;
  names[3][i] = t ;
 }

 printf ( "\nNew: %s %s", &names[2][0], &names[3][0] ) ;
}

WAP to search a string in two dimensional array


/*WAP to search a string in two dimensional array */
#include<stdio.h>
#include<conio.h>
#define FOUND 1
#define NOTFOUND 0
main( )
{
 char  masterlist[6][10] = {
       "akshay",
       "parag",
       "raman",
       "srinivas",
       "gopal",
       "rajesh"
         } ;
 int  i, flag, a ;
 char  yourname[10] ;
 printf ( "\nEnter your name " ) ;
 scanf ( "%s", yourname ) ;

 flag = NOTFOUND ;
 for ( i = 0 ; i <= 5 ; i++ )
 {
  a = strcmp ( &masterlist[i][0], yourname ) ;
  if ( a == 0 )
  {
   printf ( "Welcome, you can enter the palace" ) ;
   flag = FOUND ;
   break ;
  }
 }

 if ( flag == NOTFOUND )
  printf ( "Sorry, you are a trespasser" ) ;
}

WAP to Use of strcmp() function


/*WAP to Use of strcmp() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  string1[ ] = "Jerry" ;
 char  string2[ ] = "Ferry" ;
 int  i, j, k ;

 i = strcmp ( string1, "Jerry" ) ;
 j = strcmp ( string1, string2 ) ;
 k = strcmp ( string1, "Jerry boy" ) ;

 printf ( "\n%d %d %d", i, j, k ) ;
}

WAP to Use of strcat() function


/*WAP to Use of strcat() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "Folks!" ;
 char  target[30] = "Hello" ;

 strcat ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

WAP to copy string without changing source string


/*WAP to copy string without changing source string */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "codezworld" ;
 char  target[20] ;

 xstrcpy ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

void xstrcpy ( char *t, const char *s )
{
 while ( *s != '\0' )
 {
  *t = *s ;
  s++ ;
  t++ ;
 }
 *t = '\0' ;
}

Sunday, September 19, 2010

WAP that look-alike of the function strcopy( )


/*WAP that look-alike of the function strcopy( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "codezworld" ;
 char  target[20] ;

 xstrcpy ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

xstrcpy ( char  *t, char  *s )
{
 while ( *s != '\0' )
 {
  *t = *s ;
  s++ ;
  t++ ;
 }
 *t = '\0' ;
}

WAP to Use of string copy strcopy() function


/*WAP to Use of string copy strcopy() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  source[ ] = "codezworld" ;
 char  target[20] ;

 strcpy ( target, source ) ;
 printf ( "\nsource string = %s", source ) ;
 printf ( "\ntarget string = %s", target ) ;
}

WAP that look-alike of the function strlen( )


/*WAP that look-alike of the function strlen( ) */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  arr[ ] = "codezworld" ;
 int  len1, len2 ;

 len1 = xstrlen ( arr ) ;
 len2 = xstrlen ( "A blog of programs" ) ;

 printf ( "\nstring = %s length = %d", arr, len1 ) ;
 printf ( "\nstring = %s length = %d", "A blog of programs", len2 ) ;
}

xstrlen ( char  *s )
{
 int  length = 0 ;

 while ( *s != '\0' )
 {
  length++ ;
  s++ ;
 }

 return ( length ) ;
} 

WAP to find length of string using strlen() function


/*WAP to find length of string using strlen() function */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  arr[ ] = "codezworld" ;
 int  len1, len2 ;

 len1 = strlen ( arr ) ;
 len2 = strlen ( "A blog of programs" ) ;

 printf ( "\nstring = %s length = %d", arr, len1 ) ;
 printf ( "\nstring = %s length = %d", "A blog of programs", len2 ) ;
}

WAP to Input of strings containing spaces


/*WAP to Input of strings containing spaces */
#include<stdio.h>
#include<conio.h>
main( ) 
{
 char  name[25] ;

 printf ( "Enter your full name " ) ;
 gets ( name ) ;
 puts ( "Hello!" ) ;
 puts ( name ) ;
}

WAP to input & print a string


/*WAP to input & print a string */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[25] ;
 printf ( "Enter your name " ) ;
 scanf ( "%s", name ) ;
 printf ( "Hello %s!", name ) ;
}

Saturday, September 18, 2010

WAP to Using pointer to access array elements


/*WAP to Using pointer to access array elements */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Goldfish" ;
 char  *ptr ;

 ptr = name ;  /* store base address of string */

 while ( *ptr != `\0' )
 {
  printf ( "%c", *ptr ) ;
  ptr++ ;
 }
}

WAP to demonstrate printing of string 2


/*WAP to demonstrate printing of string 2*/
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Klinsman" ;
 int  i = 0 ;

 while ( name[i] != `\0' )
 {
  printf ( "%c", name[i] ) ;
  i++ ;
 }
}

WAP to demonstrate printing of a string


/*WAP to demonstrate printing of a string */
#include<stdio.h>
#include<conio.h>
main( )
{
 char  name[ ] = "Goldfish" ;
 int  i = 0 ;

 while ( i <= 9 )
 {
  printf ( "%c", name[i] ) ;
  i++ ;
 }
}

ADS

How to earn online

How to earn online:
Step - 1 :
signup for PayPal, to recieve your online earning
click here:
https://www.paypal.com/in/mrb/pal=CZ7224TZBMCBL
step - 2 : Singup these 4 sites & earn & enjoy! Read site to know how to earn.
1. trekpay
Earn up to $0.02 (2 cents) per click.
http://www.trekpay.com/?ref=34690
2. neobux
Earn up to $0.02 (2 cents) per click.
Click here:
http://www.neobux.com/?r=Moneyearner786

AddMe

Bookmark and Share