Ilya
memcpy is fast but runtime-dangerous
Thierry
afaik you can directly assigned struck valule when declaring it if both have same type. like T mystruct = arr; cmiiw
in my usecase theyre not the same type. thus giving me an the following: error: assignment to expression with array type
Ilya
Because you are copying pointer I think
Thierry
it works with memcpy but i find it ugly
Thierry
let me show you the code real quick
Ilya
Sure
Thierry
typedef struct _float3 { float x; float y; float z; } float3; typedef struct _tri { float3 A; float3 B; float3 C; } typedef struct _icosa { tri faces[20]; ... } icosa; ... // later in main tri faces[] = { (tri) { ... }, ... (tri) { ... } }; icosa *icosahedron = (icosa *) calloc(1, sizeof(icosa)); // check if not null icosahedron->faces = faces; // gives above error memcpy(icosahedron->faces, faces, 20); // works
Ilya
There is error because you are trying to put the expression to pointer variable
Ilya
If you want to do so, you need to pass the reference to the pointer
Thierry
like this? &icosahedron.faces = faces
Ilya
No
Ilya
Refernce should be on other side
Ilya
You cant copy the array directly. But you can make one array to point on another. But it isn't copy
NONAME
Hello Can anyone please help me with a "YES or NO " have I did the code well for this equation? 👉y=cos(45⁰)+log10(2x+1)+sin(45⁰) __________________________________ #include <iostream> #include <math.h> using namespace std; int main() { const double pi = 3.14159265; const unsigned short int kendi = 45; double y1, y2, y3, x; y1=cos(kendi*(pi/180)); y2=log10(2*x+1); y3=sin(kendi*(pi/180)); cout <<"cos(45): "<< y1 <<"\nlog10(2x+1): "<< y2 <<"\nsin(45): "<< y3 <<"\n\ny= " << y1+y2+y3 << endl; return 0; }
Ilya
@thmeier you also can use for loop to copy an array step by step
Hmaada
hello everyone i have a problem with my WSL runing i tried to run a multithread program but it seams that there are some pthread priority , is there anyone who can help me please there is my error : __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= fifo_min_prio && new_prio <= fifo_max_prio)' failed.
Ilya
Youre welcome
Thierry
so did you mean like this? icosah->faces = &faces
Thierry
because this gives me still an error >.<
Ilya
Sorry. I've disoriented you. You can use reference in some other cases...Just use memcpy() or for loop :)
Ilya
Dont care about it
Thierry
haha okay 😄
Ilya
C looks ugly sometimes. In C++ you will have std::array, std::vector and copy constructors
Thierry
thanks i appreciate it :)
𝗠𝗿.𝗕𝗘𝗔𝗦𝗧
Anyone teech me how to learn C/C+ program
Anonymous
a good start it learncpp.com annd just try to apply what you learned in small programs
Igor🇺🇦
You while condition is wrong.
Anonymous
Default constructors have no parameters. But does defining the body of a default constructor make it a custom one?
Anonymous
Default constructors have no parameters. But does defining the body of a default constructor make it a custom one?
No, you just make it non-trivial (before C ++ 17), you could make it custom by changing the function signature.
Dima
lol
Anonymous
hi I have a c++ lab exam tomorrow can anyone help me thanks
Anonymous
Anuj
Hello friends
Anuj
I need your help guys
Ibrahim
Can anyone help me I can't use or Find any tool in Toolbox Visual studio community 2019
g3rm4n
hey guys, i had a BSOD and 2 C++ files from project won't saved. there is a way to recover it?
ברני
By helping you mean help you to cheat?
Hey Danya, long time wasn't here, Can I ask an irrelevant question? (2 actually because of that one LOL) Is it ok to ask where can I find a professional computer's language coders that wants to create stuff and if it will succeed they will be paid for it? TY and sorry on advance if it's not a cool question
Anonymous
Don't.. wait for it..
Anonymous
Know
ברני
Lol OK ty :) maybe some one else know?
Lim
How to draw a circle using c?
Lim
I try to use this👇🏻,but I only get a semicircle #include <stdio.h> #include <stdlib.h> int main() { float x,y; for(y=0.5;y>=-0.5;y-=0.05){ for(x=-0.5;x<=0.5;x+=0.05){ if(x*x+y*y-0.5*0.5<=0){ printf("*"); } }printf("\n"); } return 0; }
ZukiZest
Using c and c±+ on my iphone code compiler
ZukiZest
Pretty easy
Anonymous
Hi everyone
Mr.AL-Aramy
Hello everyone
Mr.AL-Aramy
How are you?
Mr.AL-Aramy
#include<iostream> using namespace std; class Emp { private: int ID; string Name; string Address; int Phone; public: void setInfo() { cout<<"\nEnter data\n"; cout<<"\nEnter the id: "; cin>>ID; cout<<"\nEnter the name: "; cin>>Name; cout<<"\nEnter the Address: "; cin>>Address; cout<<"\nEnter the phone: "; cin>>Phone; } void getInfo() { cout<<"\n The id: "<< ID <<"\n"; cout<<"\n The name: "<< Name <<"\n"; cout<<"\n The address: "<< Address <<"\n"; cout<<"\n The phone: "<< Phone <<"\n"; } }; class EMP_SAL: public Emp { private: double Salary; public: void setSal() { cout<<"\nEnter the salary: "; cin>>Salary; } void getSal() { cout<<"\n The salary: "<< Salary ; } }; class EMP_hours: public Emp { private: int NO_of_hours; double cost_hours; public: void setInfohou() { cout<<"\nEnter the number of job's hours: "; cin>>NO_of_hours; cout<<"\nThe cost of hour: "; cin>>cost_hours; } void getinfohou() { cout<<"\n The number of job's hours: "<<NO_of_hours<<"\n"; } void get_amount() { cout<<"\n The mount is: "<<(NO_of_hours*cost_hours); } }; int main() { EMP_SAL e; EMP_hours h; e.setInfo(); e.setSal(); cout<<"-------------------------"<<endl; cout<<"Display Data"<<endl; e.getInfo(); e.getSal();cout<<"$"; cout<<"\n\n&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl; h.setInfo(); h.setInfohou(); cout<<"-------------------------"<<endl; cout<<"Display Data"<<endl; h.getInfo(); h.getinfohou(); h.get_amount(); cout<<"$"; cout<<"\n\n&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
Mr.AL-Aramy
#include<iostream> using namespace std; class Emp { private: int ID; string Name; string Address; int Phone; public: void setInfo() { cout<<"\nEnter data\n"; cout<<"\nEnter the id: "; cin>>ID; cout<<"\nEnter the name: "; cin>>Name; cout<<"\nEnter the Address: "; cin>>Address; cout<<"\nEnter the phone: "; cin>>Phone; } void getInfo() { cout<<"\n The id: "<< ID <<"\n"; cout<<"\n The name: "<< Name <<"\n"; cout<<"\n The address: "<< Address <<"\n"; cout<<"\n The phone: "<< Phone <<"\n"; } }; class EMP_SAL: public Emp { private: double Salary; public: void setSal() { cout<<"\nEnter the salary: "; cin>>Salary; } void getSal() { cout<<"\n The salary: "<< Salary ; } }; class EMP_hours: public Emp { private: int NO_of_hours; double cost_hours; public: void setInfohou() { cout<<"\nEnter the number of job's hours: "; cin>>NO_of_hours; cout<<"\nThe cost of hour: "; cin>>cost_hours; } void getinfohou() { cout<<"\n The number of job's hours: "<<NO_of_hours<<"\n"; } void get_amount() { cout<<"\n The mount is: "<<(NO_of_hours*cost_hours); } }; int main() { EMP_SAL e; EMP_hours h; e.setInfo(); e.setSal(); cout<<"-------------------------"<<endl; cout<<"Display Data"<<endl; e.getInfo(); e.getSal();cout<<"$"; cout<<"\n\n&&&&&&&&&&&&&&&&&&&&&&&&&"<<endl; h.setInfo(); h.setInfohou(); cout<<"-------------------------"<<endl; cout<<"Display Data"<<endl; h.getInfo(); h.getinfohou(); h.get_amount(); cout<<"$"; cout<<"\n\n&&&&&&&&&&&&&&&&&&&&&&&"<<endl;
Inheritance in OOP
Anonymous
Thank u sir
.
Is there any way i can run music file in c++ i mean open and play. kindly guide me
Anonymous
Plz help
klimi
Anonymous
Hi, I have a question and I have to get the answer. Can anyone help me؟
Mɾ Nαƚαɳ︎︎︎︎︎︎
write cpp code that swaps the values of variables by using 3rd variables.
Ausir
Hi guys, I can't find out how to check if I'm in the corner or near a bound of a 2d array. The idea is: put a 1 in the array if the 8 cells around the cell where i have to put a 1 are 0, so I need to verify if the 8 cells are 0 before I put the 1 in the cell chosen so I need to know if the cell where I'll put the 1 are in the corner or near the side bound. I'm sorry for my bad english I hope it's clear enough
Anonymous
Can i set file pointer at the end after i opened my file? I tired fseek but didn't worked
Anonymous
For ex: file.txt has 123 And next time i run program i want to append from last
Anonymous
So how can i do that Even i use fseek it only append from start
Anonymous
Now don't tell me google it
Anonymous
It already searched for solutions