How to find the index of the last space in string with C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    char s[64] = "c python c++ java c++ php c++";
    char ch = ' ';
    char *p = s;

    int last_index;
    while( (p = strchr(p, ch)) ) {
        last_index = p - s;
        p++;
    }

    printf("%d", last_index);


    return 0;
}





/*
run:

25

*/

 



answered Feb 16, 2022 by avibootz

Related questions

1 answer 79 views
1 answer 87 views
1 answer 92 views
1 answer 89 views
1 answer 79 views
...