ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

LANGUAGE C

Pointers & Strings

     An array and pointers are closely related and strings are also one dimensional array, strings too will be closely related to pointers.

     Many of the C library functions that work with strings use pointers.In the given below example, strchr() takes as arguments a sttring and a character to be searched for in that string.

#include <stdio.h>
main ()
{
char a, str[81], *ptr , *strchr();
printf("\nSentence to be searched :\n"); 
gets (str) ;
printf("\nEnter character to search for:");
a = getche ( ) ;
ptr = strchr(str, a);
printf("\nString starts at address %u.\n", str) ;
printf("\nFirst occurrence of char is address %u. \n", ptr);
printf("\nPosition of first occurrence(starting from 0) is %d", ptr-str);
}

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here