Ehsan
lol
Ehsan
#best
Ehsan
🙂 🙂
RC
How to combine struct to a function in c??
Anonymous
How to combine struct to a function in c??
I mean this is possible, but very unlikely what you need. What exactly are you trying to do?
Anonymous
In short for a struct to become a function you would need to have a static char array with the opcodes of the compiled function you want. You can then have a function pointer pointing to the beginning of that array. Make sure that the memory region the array resides in is actually executable. But yeah, as said this is very unlikely what you need and so far i have only seen this being used in hacky and/or malicious projects.
RC
I mean this is possible, but very unlikely what you need. What exactly are you trying to do?
#include <stdio.h> typedef struct { int number,age; char name[50],info[100]; } follow; void create(){ FILE *p; if((p= fopen("Myfile.txt","w")==NULL));{ puts("File could not be found!"); } else{ follow records{1, "", "",2}; for (int i = 1; i <= 100; i++) { fwrite(&records, sizeof(follow), 1, p); } fclose(p); } } int main(){ create(); }
Andrew
Check brackets in your first “if” statement in ‘create’ function. I think you should close bracket after ‘p=fopen(…)’
RC
Maybe it's in follow records={..}!
Andrew
Only that?
I don’t know that’s only what I noticed at first reading:) Sorry for bad English
Nik0
good
Ausir
Hi guys, I need some info. What tf is wrong with SIGUSR1? I'm using sigaction and kill sending SIGUSR1, the process that should receive the signal just ignore it, just SIGUSR1, I changed SIGUSR1 with SIGPIPE, just for debugging, and it's work fine. Can someone explain me wtf is going on? I'm losing hope. TY
klimi
He he "real scratch" meaning not std lib nor graphical api? Must be fun
H
Hello guys, This is my project. There are errors. Can someone help me solve it? This is the title of the project Car rental management system (add, search, edit, and remove cars), functions for renting cars for a specific period.
H
#include <iostream> using namespace std; struct Cars string mark &#91:10] = {"Hyundai", "BMW". "Mercedes", "Audi". "Tesla","Skoda", "Volkswagun". "Toyota". "Ford"); string model &#91:10]= {"2016MD":"2018AS","2018DS","2017LA", "20180W","2005Ps","2008PW","2010QW", "2016SA"}; string color &#91:10]={"Red", "black","yellow", "Blue","Red","Brown","Silver", "Black","grey"); string maxs_peed &#91:10]={"100 Km/h","150 Km/h","150 Km/h","170 Km/h","130 Km/h","140 Km/h","130 Km/h","120 Km/h","150 Km/h"); int price [ 10 ]={100.200.300.500.200.250.400.600.900} ; int date &#91:10] = {2010,2012,2013,2017,2018,2005,2008,2010,2014}; struct Lessee string Name &#91:10]; string Natio_ID [10): int payment_acc [ 10) : }; //Declaring struct Cars car Lessee lessee; //First output void Minu o { int num=1; for(int i=0;i&lt:9;+11) { cout<<" titit": cout<<"Enter" <<num<<"\t- To Select "<<car.mark[i]<<endl; num++; } } //Second output void Details (int the Choice) { system("CLS"); cout<&lt:"n\n'n titt- cout<<" titit You Have Selected - "<<car.mark[the Choice-1]<<endl; cout<<"\t\t\t-- ---'n 'n": cout<<" titit Model : "<<car model&#91the Choice-1]<<endl; cout<<"\t\t\tColor : "<<car.color&#91 the Choice-1]<<endl; cout<<" tittMaximum Speed: "<<car.maxs_peed&#91 theChoice-1]<<endl; cout<<"\t\t\tPrice : "<<car.price[the Choice-1]<&lt:"K"<<endi: } //check lessee credit void check (int i) { if(lessee.payment_acc&#91:]] >= car.price&#91:j]) cout<<"\n\n\n\t\t\tProcess has been done successfully!!" <<endl; else cout<<"\n\n\n\t\t\t Not Available " <<endl; } //User Inputcpo void user_input (int theChoice) { system("CLS"); int i=the Choice-1 ; cout<<" te cout<<" te tPlease Provide Your Personal Details : \n"; cout<<" telt cout<<"n NOTE: PROVIDE FIRST NAME ONLY, DONOT ENTER SPACE WHILE PROVIDING NAME, 'n PAYMENT WON'T PROCEED IF THE GIVEN AMOUNT IS LESS THEN THE RATE OF CAR'n'n\n\n"; cout<<" the tEnter Your Name : "; cin>>lessee. Name&#91.j] cout<<" tit Enter Your National ID :": cin>>lessee.Natio_ID&#91:]: cout<<" te Payment Amount": cin>>lessee.payment_acc&#91.j]; check(i): } int main { int login: login: string decide="yes" ; cout<<" titt------ cout<<" tit SIMPLE CAR RENTAL SYSTEM n"; cout<<" titleWelcome to Our Company, Choose from the menu : "<<endl; cout<<" titt while( decide!="exit") Minuo: cout<<"\n\n\n titt Your Choice:"; int the Choice cin>>theChoice; Details(the Choice); cout<<"n'n'ntit Are You Sure, you want to rent this Car? (yes/no/exit):", cin>>decide : if(decide=="yes") { user_input(the Choice): cout<<"\n\n\tit tDo you want to continue ?(yes/no)"; cin>>decide: if (decide=="no") break; system("CLS"); } else { if(decide=="no") { system("CLS"); continue ; } else if (decide=="exit") { system("CLS"); cout<<"\n\n\n\t\t\tBrought To You By code-projects.org": break; } } } return 0; } ##??? int login({ string pass=""; char ch; cout <<"\n\n\n\n\n\n\n\t\tititit Simple Car Rental System Login"; cout << "n'n'n'n'n'n'n titttttEnter Password": ch= _getch(); while(ch != 13){//character 13 is enter pass.push_back(ch): cout <<'*; ch = _getch(); } if(pass == "pass") { cout << "n\n\n\n\t\tititit Access Granted! Welcome To Our System 'n'n"; system("PAUSE"): system("CLS"); }else{ cout << "n\n\n'n titititit Access Aborted. Please Try Again!!\n"; system("PAUSE"); system("CLS"); login: } }
klimi
#include <iostream> using namespace std; struct Cars string mark &#91:10] = {"Hyundai", "BMW". "Mercedes", "Audi". "Tesla","Skoda", "Volkswagun". "Toyota". "Ford"); string model &#91:10]= {"2016MD":"2018AS","2018DS","2017LA", "20180W","2005Ps","2008PW","2010QW", "2016SA"}; string color &#91:10]={"Red", "black","yellow", "Blue","Red","Brown","Silver", "Black","grey"); string maxs_peed &#91:10]={"100 Km/h","150 Km/h","150 Km/h","170 Km/h","130 Km/h","140 Km/h","130 Km/h","120 Km/h","150 Km/h"); int price [ 10 ]={100.200.300.500.200.250.400.600.900} ; int date &#91:10] = {2010,2012,2013,2017,2018,2005,2008,2010,2014}; struct Lessee string Name &#91:10]; string Natio_ID [10): int payment_acc [ 10) : }; //Declaring struct Cars car Lessee lessee; //First output void Minu o { int num=1; for(int i=0;i&lt:9;+11) { cout<<" titit": cout<<"Enter" <<num<<"\t- To Select "<<car.mark[i]<<endl; num++; } } //Second output void Details (int the Choice) { system("CLS"); cout<&lt:"n\n'n titt- cout<<" titit You Have Selected - "<<car.mark[the Choice-1]<<endl; cout<<"\t\t\t-- ---'n 'n": cout<<" titit Model : "<<car model&#91the Choice-1]<<endl; cout<<"\t\t\tColor : "<<car.color&#91 the Choice-1]<<endl; cout<<" tittMaximum Speed: "<<car.maxs_peed&#91 theChoice-1]<<endl; cout<<"\t\t\tPrice : "<<car.price[the Choice-1]<&lt:"K"<<endi: } //check lessee credit void check (int i) { if(lessee.payment_acc&#91:]] >= car.price&#91:j]) cout<<"\n\n\n\t\t\tProcess has been done successfully!!" <<endl; else cout<<"\n\n\n\t\t\t Not Available " <<endl; } //User Inputcpo void user_input (int theChoice) { system("CLS"); int i=the Choice-1 ; cout<<" te cout<<" te tPlease Provide Your Personal Details : \n"; cout<<" telt cout<<"n NOTE: PROVIDE FIRST NAME ONLY, DONOT ENTER SPACE WHILE PROVIDING NAME, 'n PAYMENT WON'T PROCEED IF THE GIVEN AMOUNT IS LESS THEN THE RATE OF CAR'n'n\n\n"; cout<<" the tEnter Your Name : "; cin>>lessee. Name&#91.j] cout<<" tit Enter Your National ID :": cin>>lessee.Natio_ID&#91:]: cout<<" te Payment Amount": cin>>lessee.payment_acc&#91.j]; check(i): } int main { int login: login: string decide="yes" ; cout<<" titt------ cout<<" tit SIMPLE CAR RENTAL SYSTEM n"; cout<<" titleWelcome to Our Company, Choose from the menu : "<<endl; cout<<" titt while( decide!="exit") Minuo: cout<<"\n\n\n titt Your Choice:"; int the Choice cin>>theChoice; Details(the Choice); cout<<"n'n'ntit Are You Sure, you want to rent this Car? (yes/no/exit):", cin>>decide : if(decide=="yes") { user_input(the Choice): cout<<"\n\n\tit tDo you want to continue ?(yes/no)"; cin>>decide: if (decide=="no") break; system("CLS"); } else { if(decide=="no") { system("CLS"); continue ; } else if (decide=="exit") { system("CLS"); cout<<"\n\n\n\t\t\tBrought To You By code-projects.org": break; } } } return 0; } ##??? int login({ string pass=""; char ch; cout <<"\n\n\n\n\n\n\n\t\tititit Simple Car Rental System Login"; cout << "n'n'n'n'n'n'n titttttEnter Password": ch= _getch(); while(ch != 13){//character 13 is enter pass.push_back(ch): cout <<'*; ch = _getch(); } if(pass == "pass") { cout << "n\n\n\n\t\tititit Access Granted! Welcome To Our System 'n'n"; system("PAUSE"): system("CLS"); }else{ cout << "n\n\n'n titititit Access Aborted. Please Try Again!!\n"; system("PAUSE"); system("CLS"); login: } }
You have copied this from some website right?
H
I got this from my group
klimi
Right, so its not your code and you dont understand it... Nice
klimi
Firstly, remove the HTML entities with some online convertor...
Anonymous
Can someone tell me how I should proceed after completing DSA foundations with popular problems? I give CC challenges. I've decided to at least continue and do some problems on Hackerrank (maybe until I get a 5*). What should I do in par with it, to enhance my problem solving skills? Should I start solving on Codeforces then or GFG/ Leetcode? PS : I'm in 2nd year
olli
I got this from my group
"Brought To You By code-projects" - doesn't sound like a group [1]
Anonymous
any one who is good at c++
Anonymous
any one who is good at c++
dontasktoask.com Also, it's a C/C++ channel
Anonymous
Do real projects.
I did web dev projects last sem. Would do some more and something on Data Science.
Anonymous
exercism.io has some cool challenges, pretty difficult but then again I've only been at this for a few weeks
After consulting from a number of people, I've decided to go for Codeforces once I complete what I'm doing
Anonymous
Because I don't think I can pull off hard questions at first. So lemme get a good hang of it
Anonymous
just a suggestion
Anonymous
Yea I will.
Nish
try hacker rank
I am not a programmer but my job involves writing python scripts and interacting with different APIs, which I am good at. But I suck at solving hackerrank type of questions. I've tried going through some data structures and algorithms courses. Any tips on what should I be learning if the end goal is to be able to solve those hackerrank / leetcode challenges?
Nish
Or if there are any specific books / course I can read or take.
Nish
for leetcode just open user solution.
That's what I do right now but what beats me down is I am mostly not able to solve them by myself.
Nish
interracting with APIs isnt hard. Problem solving is the part where you'll have to think a lot.. just keep on practicing, see solved solutions for the particular problem and learn how they implemented the code etc..
Agreed and that's where I struggle since I haven't really studied science or engineering. Are there any specific books or course you think can help ? The ones that's structured well and with good examples preferably
Suka
That's what I do right now but what beats me down is I am mostly not able to solve them by myself.
hmm usually by reading and studying the solution i can understand the logic or algorithm but some time i have to write simple main function to debug the test.
V01D
Why does this code segfault when I use new? https://pastebin.com/L9YsbwV4
V01D
I'm trying to allocate memory for a function upon construction
z
Why does this code segfault when I use new? https://pastebin.com/L9YsbwV4
You will have stackoverflow because your constructor is recursive to itself. And this recursive will never end until you got stackoverflow and then segfault.
V01D
ohh
V01D
why is it recursive?
z
why is it recursive?
new a will call a() constructor. So you call a() constructor inside a() constructor.
V01D
oh I see. So how would I go about allocating memory when a class is constructed
V01D
Like a logging class, I have a logging class that will be used alot and I wanna be able to just `Log().info("foo")`without worrying about manual memory allocation
z
I mean, allocate memory for what?
V01D
The class itself
V01D
or the object
z
The class itself
The class itself has its own memory.
V01D
yeah then it was an object
z
this is the pointer to it.
V01D
But I need to allocate memory for some function if I use it alot right
V01D
Why else would I see foo_class *foo_obj = new foo_class()
z
Why else would I see foo_class *foo_obj = new foo_class()
It totally make sense to be done. But not recursive constructor that calls itself.
Anonymous
Does anyone know how to define a specialisation of a template using typename, where it executed on part when it is double/int and the other when we it gets first iterator of type string
Anonymous
Hello all I AM Ankit Kumar and I have five years of experience in website development
Jasur Fozilov 🐳
Is the hacking.cpp website good or bad for learning c ++?
Mahi_way❤
Does any one over here have any experience in site reliability engineering?😇
Mahi_way❤
i.e in Testing department, related!!
Sandeep
// C++ implementation of the approach #include <bits/stdc++.h> using namespace std; // Function to return the maximum profit // that can be made after buying and // selling the given stocks int maxProfit(int price[], int start, int end) { // If the stocks can't be bought if (end <= start) return 0; // Initialise the profit int profit = 0; // The day at which the stock // must be bought for (int i = start; i < end; i++) { // The day at which the // stock must be sold for (int j = i + 1; j <= end; j++) { // If byuing the stock at ith day and // selling it at jth day is profitable if (price[j] > price[i]) { // Update the current profit int curr_profit = price[j] - price[i] + maxProfit(price, start, i - 1) + maxProfit(price, j + 1, end); // Update the maximum profit so far profit = max(profit, curr_profit); } } } return profit; } // Driver code int main() { int price[] = { 100, 180, 260, 310, 40, 535, 695 }; int n = sizeof(price) / sizeof(price[0]); cout << maxProfit(price, 0, n - 1); return 0; can anybody tell me the thought process to write a code like this on my own
Anonymous
hello anyone help me out to program a quadratic formula using c++
Hermann
anyone use ns3?. is possibile create custom mobility?
Anonymous
hi
Aditi s
Can we place two or more catch blocks together to catch and handle multiple types of exceptions thrown by a try block.
Sandeep
Its a simple recursion.
Yeah..but..how do I write it on my own ...
Aditi s
And does c++ compiler check if any error is caught or not
Hanz
And does c++ compiler check if any error is caught or not
compiler wouldn't be doing it, debugger should
Anonymous
https://learnxinyminutes.com/docs/c++/