Alex
check all pointers for NULL
Alex
also I don`t know about comment function
Alex
and this one int array = sizeof(line); fseek(opf, -array, SEEK_CUR); is weird
PO
also I don`t know about comment function
My program open a pnm file which contain a matrix it scann the matrix but before scanning the matrix there is a comment line which begin with #, remove comment detect that and comment() remove it
Youssef
25
How you solve it because i got another answer
Anonymous
How you solve it because i got another answer
Dm me the question again and i will show u
Nils
It's working perfectly
Oh wow, I didn't even test it before suggesting it. 😅
Nils
@PO_uria by the way... Why not just get the file format that the user wants from the filename?
Anonymous
Here's the question: codechef(dot)com/problems/HORSES And here's my code: #include <stdio.h> #include <stdlib.h> int main(void) { int i, t, n,res; scanf("%d",&t); for(i = 0; i < t; i++){ scanf("%d",&n); res = diff(n); printf("%d\n",res); } return 0; } int diff(int num){ int arr[num]; int i, min = 1000000001, j, k; for(i = 0; i < num; i++){ scanf("%d",&arr[i]); } for(i = 0; i < num; i++){ for(j = 0; j < num; j++){ k = abs(arr[j] - arr[i]); if(k < min && k != 0) min = k; } } return min; } I'm getting the correct outputs when I run with custom inputs. Can someone tell me where I'm wrong? I know this is an easy question and most of you here are pros, but any help is appreciated. Thank you.
Martin
@shshshhsll Just guessing. But it seems you are avoiding comparing the same horse by testing if k!=0 (since the same horse gives the same value)
Martin
But it is possible for k to be 0 in other conditions (ex: different horses have the same value)
PO
@PO_uria by the way... Why not just get the file format that the user wants from the filename?
Because, it doesn't ask me like that and the file is a matrix file (pnm) so it doesn't work if the format of the file and the format which user has entred don't match
Anonymous
Anonymous
I want to learn strings
Anonymous
#include <stdio.h> int main() { int x = 45; if( x > 95) { printf( "Student is brilliant\n"); } if( x < 30) { printf( "Student is poor\n"); } if( x < 95 && x > 30 ) { printf( "Student is average\n"); } }
Anonymous
Anunay
Not warning you for the sticker this time.. but don't post such stuff
Sky
thank you sir.
Anunay
You can share normal stickers
Anunay
That one was kinda nsfw
Dima
Lol
Sky
Sky
Is this ok?
Sky
Thank you Mr frog sir
Anunay
Is this ok?
Yea 😂
CappedCrusader
CappedCrusader
How to call the print() function of the class A from the object of class D in this Hybrid inheritance
CappedCrusader
How to call the print() function of the class A from the object of class D in this Hybrid inheritance anybody please
Artöm
d.A::print()
Artöm
Oh it would be ambiguous I assume
CappedCrusader
Yes
Artöm
One can do static_cast<B&>(d).A::print()
CappedCrusader
One can do static_cast<B&>(d).A::print()
It worked but why ??? Could you please elaborate this
Artöm
It is a cast to subobject b of object d. b has unambiguous (one) base A
Anonymous
Is it necessary to have deep knowledge of os for being a protocol developer?
Anonymous
Hi
klimi
Hi
Hi?
Anonymous
🤪
I_Interface
Hi?
Hi?
klimi
Hi?
Hey sergey, long time no see! still developing?
I_Interface
Hey sergey, long time no see! still developing?
At this time - no. Probably will in future.
Anonymous
N4gu4l
Hi there !
Anonymous
@GitGpAdmin
Anonymous
Admin
Anonymous
Need data structures pdf latest version
Nils
Hi, is there any number type that somehow, magically, can hold as big numbers as the memory allows?
Francisco
Hi, is there any number type that somehow, magically, can hold as big numbers as the memory allows?
You have to use GMP or some multiprecision library. There's nothing lika big int in the standard
piyush
/get
Mohammed Athar
Hi
Mohammed Athar
I Am New friends
Dima
Hey New
I_Interface
Hey New
Hey Dima
Mohammed Athar
Yes
Indolent
Can anyone explain to me what is happening in this code?
Indolent
https://pastebin.com/9A0QN48L
Indolent
Most importantly how can we pass it as "vec2" on line 10? It should be something like &vec2 right? How is it still working?
Artöm
https://pastebin.com/9A0QN48L
vec2 and vec1 have the same type
Anonymous
Hello. size_t func(size_t num) { return num; } int main() { size_t k = 2; size_t n = func(k); std::cout « n « std::endl; }
Anonymous
Why n print to me like 0?
Anonymous
https://pastebin.com/3Y4sFFGy When enter to if (current_sum == sol_number) and sol_size is different to 0 in ligne 6 print ZERO
Anonymous
/* * In this example, we design an algorithm that calculates the monthly paycheck of a salesperson * at a local department store. * Every salesperson has a base salary. * The salesperson also receives a bonus at the end of each month, based on the following criteria: * If the salesperson has been with the store for five years or less, * the bonus is $10 for each year that he or she has worked there. * If the salesperson has been with the store for more than five years, * the bonus is $20 for each year that he or she has worked there. * The salesperson can earn an additional bonus as follows: * If the total sales made by the salesperson for the month are at least $5,000 * but less than $10,000, he or she receives a 3% commission on the sale. * If the total sales made by the salesperson for the month are at least $10,000, * he or she receives a 6% commission on the sale. */ #include <iostream> using namespace std; int main() { cout << "******************************************\n"; cout << "***EMPLOYEE'S MONTHLY SALARY CALCULATOR***\n"; cout << "******************************************\n"; string name; int years; double sales; double baseSalary; int bonus; int commission; if(years <= 5) bonus = 10 * years; else bonus = 20 * years; if(sales < 5000) commission = 0; else if(sales >= 5000 && sales < 10000) commission = 0.03 * sales; else commission = 0.06 * sales; int maxSalary = baseSalary + bonus + commission; cout << "Name: "; cin >> name; cout << "Working Period (Years): "; cin >> years; cout << "Sales: $"; cin >> sales; cout << "Base Salary: $"; cin >> baseSalary; cout << "Salary: $" << maxSalary; return 0; }
Anonymous
Can anyone help me to figure out what is wrong with the code?
Anonymous
After compiling, I get Salary as 0.
Anonymous
I kept on staring and I just realized it was all my arrangement of the inputs. Fixed it. Thanks.
Patrick
Hello, how can I ensure a copy constructor copies into a blank object rather than an already instantiated one? It is causing a really nasty bug for me previously gone unnoticed
Patrick
I know what object it's pointing to, and it's not blank
Patrick
In the error, *this is a pointer inside my &obj, which is causing a recursive issue
Patrick
generally I watch the copy constructor copy into a blank *this
Naman
Are you passing the object by reference inside copy constructor?
Patrick
and for the first hit in a particular function it is blank... but the second time it's not
Naman
generally I watch the copy constructor copy into a blank *this
It depends on which object we are calling copy constructor