How to find a character in char array in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[32] = "Quickly get a project started", *p;
 
    p = (char *)memchr(s, 'g', 32);
    if (p != NULL)
        printf("'g' found at index: %d\n", p - s);
    else
        printf("'g' not found\n");
 
    return 0;
}
 
 
/*
run:
 
'g' found at index: 8
 
*/

 



answered May 24, 2018 by avibootz
edited May 24, 2018 by avibootz

Related questions

1 answer 168 views
1 answer 173 views
1 answer 142 views
1 answer 224 views
1 answer 112 views
...