Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.

Monday, September 20, 2010

WAP to use array of pointers and Use of malloc


/*WAP to use array of pointers */
/* and Use of malloc */

#include<stdio.h>
#include<conio.h>
#include "alloc.h"
main( )
{
 char  *names[6] ;
 char n[50] ;
 int  len, i ;
 char *p ;

 for ( i = 0 ; i <= 5 ; i++ )
 {
  printf ( "\nEnter name " ) ;
  scanf ( "%s", n ) ;
  len = strlen ( n ) ;
  p = malloc ( len + 1 ) ;
  strcpy ( p, n ) ;
  names[i] = p ;
 }

 for ( i = 0 ; i <= 5 ; i++ )
  printf ( "\n%s", names[i] ) ;
}

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 Use of const keyword


/*WAP to Use of const keyword */
#include<stdio.h>
#include<conio.h>
main( )
{
 float r, a ;
 const float pi = 3.14 ;

 printf ( "\nEnter radius of circle " ) ;
 scanf  ( "%f", &r ) ;
 a = pi * r * r ;
 printf ( "\nArea of circle = %f", a ) ;
}

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' ;
}

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