TIP: Click on subject to list as thread! ANSI
echo: cis.languages
to: SCOTT HOWELL 70270,641
from: Jeff Dege 76426,211
date: 1990-06-14 08:27:10
subject: #4359-#help with `c` index()

#: 4363 S3/Languages
    14-Jun-90  08:27:10
Sb: #4359-#help with 'c' index()
Fm: Jeff Dege 76426,211
To: SCOTT HOWELL 70270,641

   What you need to keep in mind is that a string is an array of characters,
and the name of array variable is treated as a pointer to the first elemnt. 
Once you have a pointer to the first 'm' in a string, all you have to do is
subtract to get the index.

#include 
#include 


main()
{
   char string[80], *p;

    puts("Enter a string");
   fflush(stdin); /* flush the output buffer */

    gets(buffer);

    p = Index(string, m);

    printf("The first 'm' occurs in location %d\n", p - string);
}

   If you'll notice, if the string starts with an 'm', this program will print
0 (all C arrays start at 0.)





There is 1 Reply.

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.