Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 11:56:40 UTC, Ali Çehreli wrote: In addition to what others said, you can take advantage of ranges to separate concerns of filtering and iteration. Here are two ways: [...] Of course another help from the legend himself ;) As always thanks a lot and have an

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/21 12:21 AM, rempas wrote: >while (prompt[i] != '{' && i < len) { In addition to what others said, you can take advantage of ranges to separate concerns of filtering and iteration. Here are two ways: import core.stdc.stdio; import std.algorithm; // Same as your original void

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:54:44 UTC, zjh wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: I have the following code: `prompt[i]!='{'`,here,i=len.so `array overflow` Thanks a lot. It seems I have a lot to learn. Have an amazing day!

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:38:50 UTC, Mike Parker wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: When I execute it, I'm getting a range violation error. If I try to set "len" to be the length of the "prompt" minus 1, then it will work and it will print the "prompt" until the

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread zjh via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: I have the following code: `prompt[i]!='{'`,here,i=len.so `array overflow`

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread Mike Parker via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: When I execute it, I'm getting a range violation error. If I try to set "len" to be the length of the "prompt" minus 1, then it will work and it will print the "prompt" until the questionmark. So I cannot find where the error is...

Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
I have the following code: ``` import core.stdc.stdio; void print(T)(string prompt, T args...) { size_t len = prompt.length; size_t i = 0; while (prompt[i] != '{' && i < len) { printf("%c", prompt[i]); i++; } } void main() { print("Hello, world!\n", 10); } ``` When I