Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

String handling by pointers

Posted By: Alice Hughes     Category: C Programming     Views: 4431

Write a program using pointers to determine the length of a character string.

Code for String handling by pointers in C Programming

   main()                                                          
   {                                                                
       char  *name;                                                 
       int   length;                                                
       char  *cptr = name;                                          
       name  = "DELHI";                               
       printf (“%s\n”, name);              
       while(*cptr != '\0')                                         
       {                                                            
           printf("%c is stored at address %u\n", *cptr, cptr);     
           cptr++;                                                  
       }                                                            
       length = cptr - name;                                        
       printf("\nLength of the string = %d\n", length);             
   }                                                              
                                                                    
Output                                                           
                                           
   DELHI                         
   D is stored at address 54                                        
   E is stored at address 55                                        
   L is stored at address 56                                        
   H is stored at address 57                                       
   I is stored at address 58                                        
                                                                    
       Length of the string = 5  
  
Share: 


Didn't find what you were looking for? Find more on String handling by pointers Or get search suggestion and latest updates.

Alice Hughes
Alice Hughes author of String handling by pointers is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!