coal
c++ wont die anytime soon
coal
the standard is constantly being updated
coal
there's the c++23 revision which makes me excited
coal
it'll implement networking in the stdlib
Strife
it'll implement networking in the stdlib
I mean, it will be updated and extend its life
coal
and under what inputs does it give a segmentation fault
No Name
"1,2,3,4"
No Name
for both u and v
coal
for both u and v
./shitycode Insert the first vector : 1,2,3,4 The first vector you chose is : 1,2,3,4 Insert the second vector : 1,2,3,4 The second vector you chose is : 1,2,3,4 Insert number of dimensions : 1,2,3,4 The number of dimensions you've chosen is :1
coal
the only way i've found a segmentation fault is when n > size
No Name
uhmm ill take a look at it again, i need to figure it out, it makes me mad lol
coal
it's probably because you're exploiting undefined behavior
coal
sometimes it works sometimes it doesnt
coal
try adding an if before accessing u and v to check the value
coal
if (u[i]) { printf("%d", u[i]) }
No Name
ok will do
coal
also
coal
Insert the first vector : 1,2,3,4 The first vector you chose is : 1,2,3,4 Insert the second vector : 1,2,3,4 The second vector you chose is : 1,2,3,4 Insert number of dimensions : 10 The number of dimensions you've chosen is :10 i: 741485617 i: 3419187 i: 2013630416 i: 32766
coal
int scalar_product(int u[],int v[],int n) { int i; int w = 0; for (i = 0; i < n; i++) if (u[i]) { printf("i: %d\n", u[i]); } w += u[i]*v[i]; return w; }
coal
is this the output you're expecting? lol
No Name
surly not XD
coal
yaeh
coal
that's why you have a segfault, try not using gets
coal
instead, use scanf with many %d
No Name
ill change it to fgets
coal
yeah that's better
coal
but scanf would be the best option
coal
unless it's obligatory for you to input all the elements in the same line
coal
and if you're doing it comma-separated, use strtok as well
coal
parse it as a string first, then get all numbers from it in a for loop with strtok
coal
and append them to the array
No Name
i have a question that might sound a bit stupid, when i get the user's input for the vectors, I use fgets on array variable (v[ ]), does it make the user's input string a array already ? like automatically ?
Anonymous
I never knew programming was this hard
Anonymous
?
I would never understand this much 😢
Anonymous
yeah that's better
U seem to be an Anime freak🥳
coal
I never knew programming was this hard
it will only get harder dont worry
Dima
lol
coal
U seem to be an Anime freak🥳
that's a very accurate observation
Anonymous
that's a very accurate observation
Ha ...Is that a character from parasyte the maxim series in ur dp ?.,2nd one
coal
it was shinichi
coal
my current pfp is a fanart of maka albarn from soul eater
Anonymous
please do you have beginners code
coal
please do you have beginners code
google "c/c++ tutorial" and you'll find what you need
Anonymous
Anonymous
my current pfp is a fanart of maka albarn from soul eater
And there's a funny character from MHA ...kamaniri ryt
coal
i collect pfps
Dima
#ot pls
Anonymous
Oh i c
coal
#ot pls
yes sorry
Anonymous
yes sorry
So are u a learner or a developer
coal
So are u a learner or a developer
lets go to the OT group
Anonymous
Hello can anyone tell me can we use while loop in 2D arrays ??
Pavel
Hello can anyone tell me can we use while loop in 2D arrays ??
while loop is the most universal one, technically you can use it for most of the cases when you want to iterate over something
Pavel
I tried too much but i cant figure out how to use while loop in 2d array
How do you store the array (what is the exact type)?
Anonymous
Pavel
Can i sent you screenshot in dm?
Better to be sent as text here, to be honest, but OK
Anonymous
Better to be sent as text here, to be honest, but OK
Well ok i will try to understand you on text i am trying to store 3 x 3 in integer values
Anonymous
Everything going ok but when i call the code it give wrong out i dont know why same code run okey in nested for loop
Anonymous
Can you share the code?
#include<iostream> using namespace std; int main() { int a[3][3] = {{1 , 1 , 1}, {2, 2 , 2}, { 3 , 3 , 3}}; int i = 0 , j = 0 ; while(i<3){ while(j<3){ cout<< a[i][j]<< " "; j++ ; i++; } cout<< endl ; } return 0 ; }
Anonymous
You need to do i++ in the outer loop
sorry how ? I dont get you
Pavel
sorry how ? I dont get you
Move i++; one line below, after }
Anonymous
Move i++; one line below, after }
Still not working i tried that its outputing wrong
Anonymous
#include <iostream> using namespace std; int main() { char** cokboyutlukarakterdizisi; cokboyutlukarakterdizisi = (char*) malloc(3 * sizeof(char)); for (int i = 0; i < 3; i++) cokboyutlukarakterdizisi[i] = (char*) malloc(10 * sizeof(char)); cokboyutlukarakterdizisi[0] = "al"; cokboyutlukarakterdizisi[1] = "fa"; cokboyutlukarakterdizisi[2] = "be"; }
Anonymous
Hi, I'm trying to learn dynamic memory management on multidimensional arrays. where am i wrong?
Anonymous
😭