When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
7 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
seems to be alright
start from the end and do reverse iteration
was going to say, the printing seems fine, but the logic could probably use some work
;compile -fanalyzer```c
#include <stdio.h>
#include <stddef.h>
struct qstr {
size_t length;
size_t capacity;
char* data;
};
void qstr_rmlast (struct qstr* s, char c) {
int index = -1;
for (int i = 0; i < s->length; i++) {
if (s->data[i] == c) index = i;
}
printf("%d\n", index);
}
int main () {
struct qstr s = {5, 5, "hello"};
qstr_rmlast(&s, 'l');
}
3
works fine either way