M
OK thanks so much
Anonymous
https://pastebin.com/BmzsdsZA
Just curious. How are you compiling your code?
M
Using codeblocks
Anonymous
Usually linker will give errors only if you try compiling main.cpp alone without linking student.cpp object code. If you are doing it with Codeblocks, I think the ide should take care of it. Are all the source files in the same project?
M
Yes and I run it using online compilers and it run but I don't know why on my IDE this is happening
Anonymous
Ok will check it later in the day
Sandeep
int count( int S[], int m, int n ) { int i, j, x, y; int table[n + 1][m];
Sandeep
int count( int S[], int m, int n ) { int i, j, x, y; int table[n + 1][m];
The compiler shows that m and n should be constants..what should I do
Anonymous
The compiler shows that m and n should be constants..what should I do
Use dynamic memory allocation or better use vectors
Sandeep
Use dynamic memory allocation or better use vectors
Should it be vector<int,int> table;. ???
Anonymous
Should it be vector<int,int> table;. ???
vector<vector<int>>
Sandeep
int* table=new int[(n + 1)*m]; for (i = 0; i < m; i++) table[0][i] = 1;..........this line gives error
Sandeep
int* table=new int[(n + 1)*m]; for (i = 0; i < m; i++) table[0][i] = 1;..........this line gives error
It says expression must have pointer to object type but..it is int type
Sandeep
Sandeep
then i tried this
Sandeep
now table[0][i]=1; gives access violation error
Anonymous
Ok
the reason is that int *table is just an array of integers, not an array of arrays
Vlad
You've suggested a pointer to an array of static size
Vlad
Anyways he's got three options: 1) int** and allocate each row separately 2) index it as [i * width + j] 3) use VLA if it is C
Vlad
Or just use C++ lmao
Vlad
Although vector of vectors is still kind of questionable. I would've stuck with [i * width + j]
Anonymous
int* table=new int[(n + 1)*m]; for (i = 0; i < m; i++) table[0][i] = 1;..........this line gives error
Just use vector<vector<int>> vec (n+1, vector<int>(m,0)); You can access vec like you access a 2D array.
Amy
Why can't I send images into this box? OK, I am just coding that and no issues from compiler.
Sandeep
use table[0 * m + i]
This helped but. Now there is an error after the function is returned ..do you want to look at the code
Sandeep
Can you copy the error message?
It says exception thrown ..access violation reading location
Vlad
It says exception thrown ..access violation reading location
This is not compiler error. You must have read/written out of bounds
Vlad
Debug it
Sandeep
Debug it
Ok thanks
Sandeep
Debug it
Done fixed
Anonymous
It says exception thrown ..access violation reading location
You are probably accessing out of bounds. If you define your array as int* a = new int((n+1)*m); And if you want to access it like a[r][c] then you should instead write it as a[r*m + c] and you must make sure that r does not exceed n. Also you must make sure that r*m+c should be less than (n+1)*m. Otherwise it is Undefined Behavior.
Anonymous
This helped but. Now there is an error after the function is returned ..do you want to look at the code
use vector<vector<int>>. don't do new and delete yourself
Anonymous
Okay thanks
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es60-avoid-new-and-delete-outside-resource-management-functions
™barynium†⋆。˚🇧🇷
#include<iostream> using namespace std; int main() { int x,y; cout<<"Enter your numbers:"; cin>>x,y; { if(x>y) cout<<"x is greter number"; cout<<"y is smaller number"; else cout<<"y is greater number"; cout<<"x is smaller number"; } return 0; }
#include<iostream> using namespace std; int main() { int x,y; cout<<"Enter your first number:"; cin>>x; cout<<"Enter your second number:"; cin>>y; if(x>y){ cout<<x<<" is greter number"<<endl; cout<<y<<" is smaller number"<<endl; } else { cout<<y<<" is greater number"<<endl; cout<<x<<" is smaller number"<<endl; } return 0; } //Try this
shadow
Can someone suggest me project ideas with C++
shadow
Advanced or intermediate or basic
shadow
Pavel
Can someone suggest me project ideas with C++
TCP chat (client and server) Board game
Topigs Genetic Centre
Am asking for a road map in programming where i should start, any certifications. Thanks for your help!
Pavel
Am asking for a road map in programming where i should start, any certifications. Thanks for your help!
Programming is a huge field, what exactly you want to work with? Or at least what is interesting to you?
Topigs Genetic Centre
Ain't sure advise for entry level
Pavel
Ain't sure advise for entry level
I know a good literature roadmap for game developers, you can use the frames up to 3 as they are very generic https://github.com/miloyip/game-programmer
Vitrag
#include<iostream> using namespace std; int main() { int total; cout<<"Enter total marks:"; cin>>total; if(total>100 && total<=0) cout<<"Invalid"; else if (total>=70 && total<100) cout<<"Distinction"; else if (total>=60 && total<70) cout<<"First Class"; else if (total>=50 && total<60) cout<<"Second Class"; else if (total>=35 && total<50) cout<<"Third Class"; else cout<<"Fail!"; return 0; }
Vitrag
Instead it is showing fail what should I do
Anonymous
how can i define an overidable callback?
Anonymous
as static virtual is invalid
Vitrag
you dont want to print fail ?
It's its below 35 and more than equal to 0 then it's is fail
Vitrag
But more than 100 and less than 0 must be invalid
ram
what is the problem then >?
ram
then it will print invalid
ram
if(total>100 || total<=0)
.
Hi. Can someone help me? I have to program a function that will prevent any repetition of same numbers and combinations. I successfully did the first part (the three numbers are different from each other), but I don’t know how to make it not repeat combinations: for example if there is 789, it should’t print 987 later. #include <unistd.h> void ft_putchar(char c) { write(1, &c, 1); } void ft_print_comb(void); int main(void) { ft_print_comb(); } void ft_print_comb(void) { char a; char b; char c; char comma; char space; a = '0'; comma = ','; space = ' '; while (a <= '9') { b = '0'; while(b <= '9') { c = '0'; while(c <= '9') { if(c != a && c != b && a != b) { ft_putchar(a); ft_putchar(b); ft_putchar(c); ft_putchar(comma); ft_putchar(space); } c++; } b++; } a++; } }
Anonymous
how can i define an overidable callback?
If you want it to be overridable it cant be static obviously. Why not just agree on an interface for the callback and let the client pass in any callback that matches the interface. Why should there be an inheritance relationship at all?
Anonymous
I would do something like this for callbacks: class CallBack{ public: virtual void call()=0; }; class ExecutorService { public: virtual void run(Execute& e) final{ execute(); e.call(); } virtual void execute(){ //Can be overriden } }; This would give you flexibility with both the class that is used for handling callbacks (the executor service class above) and also with the actual callback class.
Anonymous
Since 112 and 121 are combinations of eachother
Anonymous
or do you mean, that the reverse of the number should not be printed Eg 123 and 321
Kkk
Hi guys I have an old program written in C with Labwindows and now I want do do the gui of the program in C#. How I can connect the Gui in C# with the C code? Which is the easiest way?
Anonymous
If you want truely unique numbers, than 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 20, 22, 23, 24, 25, 26, 27, 28, 29 30, 33, 34, 35, and so on until 90, 99 The same can also be applied to 100 to 1000 however it will be more complicated 100, 101, 102, 103, 104, 105, 106, 107, 108, 109 110, 111, 112, 113, 114, 115, 116, 117, 118, 119 120, 122, 123, 124, 125, 126, 127, 128, 129 130, 133, 134, 135, and so on until 190, 199 200 210, 212 to 219 220, 222 to 229 to 290, 299 300 310, 313 to 319 320, 323 to 329 And so on until idk Is difficult cus there lots of combinations that can occur 114 is same as 411 so 411 cannot occur And so on