⚛ Hz
Comment, data
⚛ Hz
Igor🇺🇦
⚛ Hz
" "
PO
guys please don't complicate this problem
PO
please I have just one day to finish it
⚛ Hz
The basic idea, read a character a time
PO
and the whole project took me 4 days
Igor🇺🇦
" "
That's not part of the task. You just need to read #. That's it. Single if statement is enough
PO
I have just to complet this function
⚛ Hz
(ok, but reading a whole line and then analyze it is not effectively way to do that...
Igor🇺🇦
⚛ Hz
By using getchar()
⚛ Hz
Only 4 cases
'0', '1', ' ', '#'
Igor🇺🇦
⚛ Hz
And starting with normal state
Assume the character is c
If c == '#' then make a loop to ignore until '\n'
⚛ Hz
If c == '0' or '1', then store it
⚛ Hz
I think we are talking about the same thing, but expressing differently
⚛ Hz
⚛ Hz
Because '#' is a trivial case, just loop getchar until '\n'
⚛ Hz
So pesudo code is (I'm using a mobile phone right now)
while (true) { switch (getchar()) {
case '#': while (true) switch (getchar()) {
case '\n': goto outer;
case -1: goto eof;
}
outer:
break;
case '0': got0(); break;
case '1': got1(); break;
case ' ': case '\n': break; // maybe you need extend it to make it fit the requirements
case EOF: goto eof;
}
}
Pavel
⚛ Hz
(btw the basic state machine model should be two level switch inside a loop
while(cond) switch(state) switch (input)
⚛ Hz
But if you want to store whole line, at first you need to know the line length
⚛ Hz
It may be larger than your local array(
⚛ Hz
Or it may cause incorrect behavior
Pavel
Doing sort of std::getline should be fine.
If you anyway care about performance you should use mmap or similar API
⚛ Hz
If the comment is 8192 characters, but you local buffer is 4096, and then you may either overwrite memory or incorrectly split the line, and make following content become "next line" but it isn't
Pavel
Yes if the input file is large enough you might get some issues . It's not a case here
Igor🇺🇦
⚛ Hz
It is a good idea to write correct code instead of "just work" code...
The state machine may not fastest way, but it is common pattern for that kind of task...
(As context free grammar parser
Igor🇺🇦
⚛ Hz
Unless you create dynamic array(or std:: string
⚛ Hz
Anyway, you still need read character one by one to extract data from your buffer
⚛ Hz
(or sscanf , that's worse
Anonymous
Anonymous
But yeah too hardcore. Checking given_string[0] == '#' was said before
Anonymous
/notes
Anonymous
/get reference-the-standard
Halil Aytaç
Tamah
Please I have a program in writing a c program to convert from decimal to a negative base
How can I do that please ??
Asad
/get great
Asad
/get best
klimi
Asad
/get awesomeness
klimi
Tamah
Tamah
I mean like I don't know the algorithm to use
Tamah
I have written a program that converts from decimal to other bases but is not working for negative base . I don't know why
Stefano
Guys what is the best way to take data from such a file: https://pastebin.com/s4LxFNGE and transfer it to an array of structures?
Stefano
I need the data between ':' and '\n'
Anonymous
Hii
Pavel
Stefano
Anonymous
Igor🇺🇦
Anonymous
Anonymous
But I'm not sure how to specify a variable length whitespace sequence in a format string
Bumpy
anyone know why its doesnt working?
Bumpy
its seems thats the recursion not going on the depth
Stefano
Anonymous
Hy guys
Anonymous
can anyone help me out in a c ++ program

Henry
Can anyone help me with a 3x3 matrix determinant code so would get the basics to solve 5x5
Igor🇺🇦
Igor🇺🇦
Henry
Henry