Elfa Metesar
np
Elfa Metesar
I am getting some weird behavior with this code: https://termbin.com/xlmf I basically made a string class (gonna be dynamically sized later on) and added some functions to it. But when it comes to printing, ostream distorts the characters whereas printf prints just fine.
Elfa Metesar
the distorted character is interpreted as some weird character like SOH in terminal
Anonymous
I am getting some weird behavior with this code: https://termbin.com/xlmf I basically made a string class (gonna be dynamically sized later on) and added some functions to it. But when it comes to printing, ostream distorts the characters whereas printf prints just fine.
Using alloca within a function (constructor) and then expecting the memory on the stack to be valid through the lifecycle of the object is Undefined Behavior. The memory allocated by alloca is invalidated at the end of the function it is called in (in your case the constructor)
Elfa Metesar
omg, and i was like "it's working so it is legal" lmao..
Elfa Metesar
thank you for that info, here i am busting my ass off to get this working
Danya🔥
MHD
#include <stdio.h> #include <stdlib.h> fun1(int ); int main(void) { int (*ptt1)(int); ptt1 = fun1; printf("%d" , ptt1(22)); return 0; } int fun1(int num) { return num*2; }
Andre
Hello, Im doing an exercise but cannot comprehend what I'm asked to do. "Write a program DETAB that replaces tabs in the input with the proper nr. of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every N columns. Should n be a variable or a symbolic parameter?" -> is it saying replace every \t with 4 ' ' ? What is a tab stop ?
Andre
And what does it mean with "assume a fixed set of tab stops every N columns " ?
Danya🔥
Hello, Im doing an exercise but cannot comprehend what I'm asked to do. "Write a program DETAB that replaces tabs in the input with the proper nr. of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every N columns. Should n be a variable or a symbolic parameter?" -> is it saying replace every \t with 4 ' ' ? What is a tab stop ?
In the context of this exercise, the program DETAB is meant to replace tabs in the input with the proper number of spaces to reach the next tab stop. A tab stop is a predefined position in a line of text where the cursor or the printed output will stop when a tab character (\t) is encountered. For example, let's assume the fixed set of tab stops is every 4 columns. If you encounter a tab character in the input, the program should replace it with the appropriate number of spaces (in this case, 4 spaces) to reach the next tab stop. Regarding your second question, "N" is a symbolic parameter that represents the number of columns between consecutive tab stops. In this case, if "N" is 4, tab stops will be every 4 columns. If "N" were 8, tab stops would be every 8 columns, and so on. The value of "N" is not a fixed constant but can be changed when running the program or defined as a variable to make it more flexible. So, the program should be able to take the input text, find tab characters, and replace them with the appropriate number of spaces based on the fixed set of tab stops every N columns.
Andre
Ok kinda got it. Still dont understand how i should handle N. I mean N is given on input or i should just have the possibility to change it before conpiling or at run time ?
Danya🔥
Ok kinda got it. Still dont understand how i should handle N. I mean N is given on input or i should just have the possibility to change it before conpiling or at run time ?
In this exercise, the handling of "N" can be done in one of two ways: Hardcoded Constant: You can set "N" as a constant value within your program's source code. This means "N" will have a fixed value that you define in your code, and it won't be changeable during runtime. For example, you can define "N" as 4, and your program will always use a fixed set of tab stops every 4 columns. Input or Runtime Parameter: Alternatively, you can make "N" a variable that is set at runtime or taken as input from the user when the program starts running. This allows you to change the value of "N" before compiling or during the program's execution. For instance, your program could prompt the user to enter the value of "N," and then it would use that value to determine the tab stops. Both approaches are valid, but using "N" as a runtime parameter provides more flexibility, as it allows you to change the tab stops without recompiling the program each time. So, if you want to make your program more versatile, it's better to handle "N" as a runtime parameter or user input.
Andre
Ok got it, thanks
Danya🔥
ChatGPT rules lol
Andre
Yet i dont understand why if I press tab someetimes it goes 2 blanks sonetimes it goes 4 sometimes 8. N need to be somehow dinamic.
Andre
Yes it does, i cant send u a video
Chat Boss
Andre sent a huge message, it has been re-uploaded as a file This doesnt solve the exercise. #include <stdio.h> #include <stdlib.h> int main() { int n =..
Andre
```
Chat Boss
Andre sent a huge message, it has been re-uploaded as a file This: #include <stdio.h> #include <stdlib.h> int main() { int n = 4; char c; while..
Anonymous
Why
Danya🔥
Message from @IMCalledGod: Hello I'm learning styles in wxWidgets but when I use SetBackGroundColour to set a background color for my static text after compiling and running my program I don't see any changes in my app My code: https://dpaste.org/0PPbn#L18
Danya🔥
What is the problem with this massage
We have a restriction on sending links within first 24h in the chat
Anonymous
We have a restriction on sending links within first 24h in the chat
Alright then But that was the path I uploaded my code in btw
Ighor
Why it may fail?
pointer number may be larger than 32 bit int
ülukyü
guys, can I write a kernel in pure C? or its impossible?
ülukyü
should me learn assembler before creating? (sorry for my bad english)
klimi
should me learn assembler before creating? (sorry for my bad english)
you don't need much assembler knowledge for writing the kernel in C, it certainly is helpful tho as you will be working on very low level. For kernel development i recommend https://wiki.osdev.org/Main_Page
ülukyü
oh, thanks
klimi
oh, thanks
no problem, if you have any more question, feel free to ask
ülukyü
👍
Agradwip
You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure.
PO
hi every one, how can I access to my functions and static varibale in file b.cpp from main.cpp ? I have b.hpp but I still get error in terminal which said: in function main undefined reference to `getMovingPlayer()'
Anonymous
hi every one, how can I access to my functions and static varibale in file b.cpp from main.cpp ? I have b.hpp but I still get error in terminal which said: in function main undefined reference to `getMovingPlayer()'
You can't access static variable defined in a translation unit from another translation unit. File scope static variables have internal linkage. You should be able to access functions on the other hand unless you have marked them as constexpr or something. Share your code on some pastebin site for people to be able to help you
PO
How is that a C/C++ question?
C++ question of cours
Anonymous
C++ question of cours
That message was not for you.
Agradwip
How is that a C/C++ question?
it is a leetcode medium level question it is a c++ question
albert
yes it is possible, look at linux
i don't think so. linux have some asm in boot
klimi
i don't think so. linux have some asm in boot
you mean the bootloader? that's not a kernel
albert
it's a part of kernel
klimi
It is not a c++ question
i wonder if we don't allow algoritmic problems at all
albert
ohh, ok...
klimi
grub2 or systemd-boot is not part of the linux kernel
albert
you are right
albert
yes,
Danya🔥
i wonder if we don't allow algoritmic problems at all
The guy just wants a solution, we do not allow that But if one doesn't understand something in a algorithmic problem, I think it is ok
C
isn't linux kernerl design in MS degree course>?
Anonymous
it is a leetcode medium level question it is a c++ question
The question you asked is an algorithm question and not related to C/C++. That requires no knowledge of C/C++ and just needs some understanding of immediate predecessor node and immediate successor node to find out where the swapped nodes must be put without altering the structure.
klimi
*kernel
what's MS degree course? do you mean masters degree course? or some microsoft certificate?
C
yea masters deggre i meant
Danya🔥
Lol
Danya🔥
> Microsoft > Linux > ceritficate
klimi
yea masters deggre i meant
Well... that would vastly depend on the university which you are studying?
klimi
> Microsoft > Linux > ceritficate
https://cloudblogs.microsoft.com/windowsserver/2015/05/06/microsoft-loves-linux/
C
oh damn i didnt realize it immediately lol
Andre
Im doing an exercise from the C programming language book. It seems simple -> change \t and spaces in a string with the proper amount of spaces or tabs to eat less memory. Example a_ _ _ _ _a should become a\t_ _ a. What would be a good approach ? i worked on it for 2 days and still having a lot of bugs. I want to rewrite everything. I was thinking 1. find amount of consecutive spaces. 2. convert amount of consecutive spaces in \t. 3. calculate amount of consecutive spaces remaining (< 4) . Reprint new string. Of course to this i need an array.
Andre
would it be possible to do the same logic without storing the string ? i suppose no, cause how can i calculate the spaces if without the array
Anonymous
would it be possible to do the same logic without storing the string ? i suppose no, cause how can i calculate the spaces if without the array
You can hold a buffer of 4 characters if a tab is 4 spaces long and store characters 4 at a time. You don't need to store the entire string then when reading the input (not advantageous from storage point of view however as you have just moved the storage from input to output stage). Whenever you encounter a space, you store whatever is in the buffer first in the output and then store the space as the first character of the buffer. If you encounter a non space character after consecutive spaces less than 4 characters long, you just store the spaces in the buffer and then start reading characters into the buffer. You could improve this a little further by doing lookahead and using a slightly bigger buffer.
Andre
sorry, im at the begginning of the book, isnt a buffer an array ?
Andre
i just know to use basic stuff in C, im new to programming
Anonymous
sorry, im at the begginning of the book, isnt a buffer an array ?
Yes it is an array but it doesn't need to be as long as the input. If your input has a lot of spaces which can be converted into tabs, then you won't be wasting a lot of space
VD
@admin What happened to the message I posted?
Danya🔥
@admin What happened to the message I posted?
The stupid bot thought it's spam I guess