⚛ Hz
Comment, data
Igor🇺🇦
You could build a simple state machine
State machine is over engineering for a single if. IMHO
⚛ Hz
State machine is over engineering for a single if. IMHO
(what if you want to handle space later(
⚛ 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🇺🇦
(ok, but reading a whole line and then analyze it is not effectively way to do that...
There is no other way anyway. You need to read line to find where it ends.
Igor🇺🇦
I have just to complet this function
Read lines using fgets, check if it starts with # and ignore all results till new line.
⚛ Hz
There is no other way anyway. You need to read line to find where it ends.
Not quite, you can just read the first character to decide if it is needed to read whole line, and if the data is only 0 and 1, there no reason to store the line, you could read character one by one
⚛ Hz
By using getchar()
⚛ Hz
Only 4 cases '0', '1', ' ', '#'
⚛ Hz
Only 4 cases '0', '1', ' ', '#'
And two state: normal state for parse data, comment state to ignore whole comment line
⚛ 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
Igor🇺🇦
And two state: normal state for parse data, comment state to ignore whole comment line
There are only 2 states - starts with # or not. Everything else is irrelevant based on description
⚛ Hz
I think we are talking about the same thing, but expressing differently
⚛ 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; } }
⚛ Hz
(btw the basic state machine model should be two level switch inside a loop while(cond) switch(state) switch (input)
⚛ Hz
It would be both easier and faster just to store the line
(getchar normally only copy a character from internal buffer, unless there no input right now (or buffer is full, but you need more
⚛ 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
⚛ 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
Pavel
Anyway, you still need read character one by one to extract data from your buffer
You shouldn't read it one by one, you can read by N(usually multiple by page_size) bytes at once and use intrinsic commands to find '\n' character. Again it's not nessesary for this task.
Anonymous
But yeah too hardcore. Checking given_string[0] == '#' was said before
Anonymous
It may be larger than your local array(
In that case it possible to use pointers not arrays and reallocate with them or simply getline(3)
Anonymous
/notes
Anonymous
/get reference-the-standard
Halil Aytaç
/notes
/notes
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
Asad
/get awesomeness
Tamah
You open your editor, write c code there and save it
I know how to write code , the issue is this particular code
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
Anonymous
Use std::regex if performance is not a concern
I think std::regex designed poorly
Pavel
i'm using C
Then just search for ':' and substr
Anonymous
Then just search for ':' and substr
I think sscanf is better here
Anonymous
But I'm not sure how to specify a variable length whitespace sequence in a format string
Bumpy
Node *delete(BinarySearchTree *bst , Node *current , int value) { if(current == NULL) return current; // first - find the node that contains the given value if (current->data < value) current->right = delete(bst,current->right,value); else if (current->data > value) current->left = delete(bst,current->left,value); else { // Now we've found the candidate node for deletion. //CASE 1: the node is a leaf if(isaLeaf(current)) { free(current); current = NULL; bst->size--; return current; } //CASE 2: the node have one child else if (current->right == NULL || current->left == NULL) { if(current->right == NULL) { // its means that the current node have left child Node *leftChild = current->left; free(current); bst->size--; return leftChild; } else { // its means that the current node have right child Node *rightChild = current->right; free(current); bst->size--; return rightChild; } } else { /*CASE 3: the node have two child , we need to search the node that contains the mimimum value of the rightsubtree */ Node *minChild = findMin(current->right); int minData = minChild->data; current->data = minData; current->right = delete(bst,current->right,minData); } } }
Bumpy
anyone know why its doesnt working?
Bumpy
its seems thats the recursion not going on the depth
Igor🇺🇦
Can I use : and \n as delimiters?
This will use delimiters any white space and new line . strtok(buffer, " \t\n")
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
Henry
Do you know how to solve the issue for 2X2 matrix?
Yeah that simple but don't for 3x3