Pointer of string:▫️ As we can have the pointer togeneral array, we can also have a pointer to string .
When we storethe string address of the string to the pointer variable, this pointer variable is called as pointer to string.
char string variable [size],*ptr;
Ex ptr = &string1[0];
Example :
#include<stdio.h>
#include<conio.h>
# include<string.h>
main( )
{
char str[80],*ptr;
int k,length,count=0, M=0, R=0, U=0, G=0, N=0, A=0, Y=0, N=0, I=0;
printf("Enter a line of text\n");
gets(str);
length=strlen(str);
ptr=str;
for(k=0;k<length;k++)
{
if( (*ptr=='m') || (*ptr=='M') )
{ M++; count++;}
if( (*ptr=='r') || (*ptr=='R') )
{ R++; count++;}
if( (*ptr=='u') || (*ptr=='U') )
{ U++; count++;}
if( (*ptr=='g') || (*ptr=='G') )
{ G++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='n') || (*ptr=='N') )
{ N++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='y') || (*ptr=='Y') )
{ Y++; count++;}
if( (*ptr=='a') || (*ptr=='A') )
{ A++; count++;}
if( (*ptr=='n') || (*ptr=='N') )
{ N++; count++;}
if( (*ptr=='i') || (*ptr=='I') )
{ I++; count++;}
Ptr++;
}
printf("Name of character present in screen = %d \n",count);
printf( "M = %d \n",Y);
printf( "R = %d \n",R);
printf( "U = %d \n",U);
printf( "G = %d \n",G);
printf( "A = %d \n", A);
printf( "N = %d \n",N);
printf( "A = %d \n",A);
printf( "Y = %d \n",Y);
printf( "A = %d \n",A);
printf( "N = %d \n",N);
printf( "] = %d \n",]);
}
Output:
Enter the line text
Mrunali is best in all student
Name of character present in screen = 12
M = 1
R = 1
U = 2
G = 0
A = 2
N = 3
Y = 0
I = 3