Anonymous
If a same macro is defined in so many files( let's say .CPP) . And we want to make change in its value such that it is reflected everywhere! Is there any way we can do it in one go rather than individually changing in each file
There is this concept called DRY in software engineering. It means "Don't Repeat Yourself". Since your code violates that principle, you have to now pay the price.
Anonymous
what mistake is there while printing friquency in this code?
cin >> n[10]; This does not accept input into an array of 10 elements like you think. This accepts input only into one location i.e. n[10]. Moreover n[10] is an invalid location because your array has elements only in positions 0 to 9. You have to use a for loop to accept inputs into the array.
Saurav
anyone please illustrate this syntax: for(int i = 1; i <= (input-'A'+1); ++i)
Anonymous
anyone please illustrate this syntax: for(int i = 1; i <= (input-'A'+1); ++i)
That’s the condition set for a for loop. It means that the code inside that loop will continue until i passes above input - ‘A’ + 1.
Anonymous
I'm not understanding "input-'A'+1" how does it work??
Unless you tell me what the variables input and ‘A’ are supposed to mean, I can’t help you.
Puspam
I'm not understanding "input-'A'+1" how does it work??
Code point of the letter 'A' according to ASCII is 65. So, it is actually input-65+1
Chat Boss
Where?
Saurav Shri sent a code, it has been re-uploaded as a file
Saurav
Code point of the letter 'A' according to ASCII is 65. So, it is actually input-65+1
OO it means it directly use the ASCII value of A rather than as we usually use 'int' as input and convert it into 'char'
Anonymous
Ok I'm sending you the source code
Apparently, your program outputs the number of each letter that number of times (A = 1, B = 2, C = 3, etc.).
Saurav
Right
thanks, I got it.
Anderson Yeo
Hi, does anyone know why im getting the error "expected declaration or statement at the end of input"? Here's the part of my code: for(i=0; i<num; i++) { fprintf(fp, "%d %s %s %s %s %s %s\n",sPui[i].puiid, sPui[i].name, sPui); }
Anonymous
```c
Chat Boss
Rida 2015 sent a code, it has been re-uploaded as a file
Anonymous
can someone compile this code and give me the output
Anonymous
it should be going from 00 01,...,98 99 to this
Anonymous
its c not c++
\Device\NUL
can someone compile this code and give me the output
> int b = a; > for (b = 0; ...) ?
\Device\NUL
its c not c++
What's the output of strace ? and why not pass the the reference of c ?
Anonymous
what strace u talking about
Anonymous
> int b = a; > for (b = 0; ...) ?
that just a normal for loop what ?
\Device\NUL
what strace u talking about
You experimenting with system call and you didn't know about strace ?
Anonymous
no i dont know about strace
\Device\NUL
that just a normal for loop what ?
if b is defined inside loop, why would you put int b = a ?
Anonymous
what u talking about
Anonymous
i define b in line 12
Anonymous
before the first for loop
Anonymous
oh u can remove the int in line 15
Anonymous
keep it only b = a
\Device\NUL
\Device\NUL
Also, 0 char on ASCII table is represented as 48 value, but the a is started from -1
Anonymous
lol a friend told me it give him 98 99 is that true ?
Anonymous
bro read the code or don't commet about it
Anonymous
if u read the code u gonna see that when i call them i add 48
Anonymous
look at line 19 and 20 +++
Anonymous
48 + a
Anonymous
and yes i can make a a char but i choose to make it an int because i can add 48 on it
\Device\NUL
48 + a
a is started from -1, 0 on ascii table is started from 48. 48 + (-1) is what ?
\Device\NUL
You can't expect to print raw byte to get printed on console
Anonymous
it start from -1 but in the first loop it will get increment
Anonymous
i hava done this in while loop and it work perfect
Anonymous
im only playing with the code because i have more time
Anonymous
can u just confirm the output of the code for me
Anonymous
then we can continue
\Device\NUL
\Device\NUL
Did you make typos at for (a = -1;a < 98;a++); notice the semicolon
Anonymous
Oww, sorry. The output is 98 99
does it give only this out put no numbers before it ?
Anonymous
like 00 01 00 02...
Anonymous
lol yeah remove those semicolon please
\Device\NUL
does it give only this out put no numbers before it ?
There maybe more stuff on stdout but the console will display the output if it's recognized.
Anonymous
remove the semicolon in line 13 and line 16 and run the code
Anonymous
sorry i mean compile and run it
\Device\NUL
remove the semicolon in line 13 and line 16 and run the code
Can't you just use online compiler '-')/ ?
\Device\NUL
Most of online compilers are hosted on Linux which has support for unistd.h headers
Anonymous
Can't you just use online compiler '-')/ ?
don't u think if i could do that i would have done it ?
\Device\NUL
Is it the way you ask for help to others ? Please calm down if you're feel stressed out
Anonymous
After learning data structures and algorithm, what can I do with c++ apart from video games
Artur
Anything
● Igor
stdin, stdout and stderr are files to unix-based systems, but are they considered files on windows and other systems?
\Device\NUL
stdin, stdout and stderr are files to unix-based systems, but are they considered files on windows and other systems?
On Windows, They're using Everything is Object instead of file (descriptor) concept. Everything on Windows is managed by things called HANDLE instead of fd
\Device\NUL
Each of Windows process has own ProcessEnvironmentBlock, The Standard HANDLE is accessed from RTL_USER__PROCESS_PARAMETERS
\Device\NUL
Also read this one https://devblogs.microsoft.com/commandline/windows-command-line-inside-the-windows-console/
● Igor
what is the proper way of handling errors here? while (1) { int ch = getc(file); if (ch == EOF) break; putc(ch, stdout); } should i check for ferror every iteration of the loop? and also i believe I should fflush inside the if and check for error again, right? since stdout is buffered by default
Thadeu
If you need to build a list of args to pass to execvp which is the most meaningful and common? char *a[1024] or char **a followed of realloc as it grows?
Thadeu
I'm asking because 1. I need to guess that the array has 1024 positions to be sufficiently large... but it is still not secure if it has 1025, and if I have just 1 I'm allocating other unnecessary 1023 slots. 2. If I use malloc/realloc and execvp successfully replaces the process a further free() will never be called
Anonymous
I'm asking because 1. I need to guess that the array has 1024 positions to be sufficiently large... but it is still not secure if it has 1025, and if I have just 1 I'm allocating other unnecessary 1023 slots. 2. If I use malloc/realloc and execvp successfully replaces the process a further free() will never be called
If I use malloc/realloc and execvp successfully replaces the process a further free() will never be called Why do you care? As a part of execvp, the memory image of the process is replaced completely. How does it matter whether the array allocated in original forked child process is freed or not. If the args array was built in the parent process, then you should still free it in the parent process.
MrZ
Who knows OpenCV, encounter a problem will not be solved, just started to learn opencv, ask for advice
MrZ
at matDst1, matDst2; cv::resize(matSrc1, matDst1, cv::Size(32, 32), 0, 0, cv::INTER_CUBIC); cv::resize(matSrc2, matDst2, cv::Size(32, 32), 0, 0, cv::INTER_CUBIC); cout<<"channels: "<<matDst1.channels()<<" type: "<<matDst1.type()<<endl; cv::cvtColor(matDst1, matDst1, COLOR_RGB2BGRA); cv::cvtColor(matDst2, matDst2, COLOR_RGB2BGRA); cout<<"channels: "<<matDst1.channels()<<" type: "<<matDst1.type()<<endl; matDst1.convertTo(matDst1, CV_32F); matDst2.convertTo(matDst2, CV_32F); cout<<"channels: "<<matDst1.channels()<<" type: "<<matDst1.type()<<endl; dct(matDst1, matDst1); dct(matDst2, matDst2);
MrZ
channels: 3 type: 16 channels: 4 type: 24 channels: 4 type: 29 terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.5.5) /home/zyq/opencv-4.5.5/modules/core/src/dxt.cpp:4417: error: (-215:Assertion failed) type == CV_32FC1 || type == CV_64FC1 in function 'dct' Aborted (core dumped)