logo

Finding a character inside a string in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { char str[] = "Hello, friend!"; char* result = strrchr(str, 'e'); if (result != NULL) { printf("Character was found!\n"); int pos = result - str; printf("Position: %d\n", pos); } else { printf("Character was not found!\n"); } return 0; }
Course thumb

The C programming language made simple