A
A
Akmal Kadirov2014-08-22 22:01:21
linux
Akmal Kadirov, 2014-08-22 22:01:21

How to find out if a string ends with a '~' character?

How can I find out if a string ends with a '~' in C?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rrooom, 2014-08-22
@kadirov

For example:

bool endsWith (char* base, char* str) {
    int blen = strlen(base);
    int slen = strlen(str);
    return (blen >= slen) && (0 == strcmp(base + blen - slen, str));
}

I
Ivan, 2014-08-22
@0neS

Far from si, but I think like this:

char string[size];
...
if (string[strlen(string)-1] == '~') {
    ...
}

N
nadom, 2014-09-19
@nadom

both answers are correct.
don't forget to connect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question