Anonymous
But why the version without malloc prints an extra char?
They both appear to work... I thought there was an issue. :/
Anonymous
yeah but the version without malloc prints an extra unwanted char
Anonymous
Also Idk why u suggest sizeof(strlen(str)+1) when sizeof(strlen(str)) works just fine
Anonymous
The standard says malloc() has to research non-overlapping memory and that [size + 1] never segfaults, on account of memory read... But always always allocate space for the terminating nul '\0', the terminating nul isn't included in strlen().
Anonymous
you're right m8
Anonymous
Please can you help me write a program for the 2 Times table using the loop
Anonymous
Hello groupies I'm a digital marketer and I'm here to help you all get your business out there to the right target audience so if you need my service feel free to contact me. best regards.
Julius
how do you control library installation paths in cmake? i have the following: install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION release CONFIGURATIONS Release) meaning to put a release build into the release folder, but cmake just ignores the destination opt. it always installs into cmake_install_prefix/lib
Anonymous
Yes
Anonymous
#include <stdio.h> struct custInfo { char custName[30]; char custTel[20]; char orderType[20]; char orderMenu[30]; int orderUnit; char modePurchase; float totalPrice; } customer[3]; struct custInfo readData(struct custInfo customer[3]) { int i; for(i=0; i<3; i++) { printf("Enter Name: "); scanf(" %[^\n]", customer[i].custName); printf("Enter Phone Number: "); scanf("%s", customer[i].custTel); printf("Enter Order Type: "); scanf("%s", customer[i].orderType); printf("Enter Order Menu: "); scanf(" %[^\n]", customer[i].orderMenu); printf("Enter Order Unit: "); scanf("%d", &customer[i].orderUnit); printf("Enter Mode Purchase: "); scanf(" %c", &customer[i].modePurchase); printf("\n"); } return customer[i]; } struct custInfo calculatePrice(struct custInfo customer[3]) { float price; int i; for(i=0; i<3; i++) { if(customer[i].orderType == "Broiler") { if(customer[i].orderMenu == "Salmon") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 60.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 60.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } else if(customer[i].orderMenu == "CatFish") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 45.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 45.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } else if(customer[i].orderMenu == "Trout") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 25.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 25.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } } else if(customer[i].orderType == "Fryer") { if(customer[i].orderMenu == "Fish Plate") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 25.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 25.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } else if(customer[i].orderMenu == "Calamari Plate") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 35.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 35.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } else if(customer[i].orderMenu == "Fish and Chips") { if(customer[i].modePurchase == 'w') { customer[i].totalPrice = 30.00 * customer[i].orderUnit; } else if(customer[i].modePurchase == 'o') { price = 30.00 * customer[i].orderUnit; customer[i].totalPrice = price - (price * 0.5); } } } } return customer[i]; } void sales(struct custInfo customer[3]) { int i; for (i=0; i<3; i++) { printf("Customer Name: %s \n", customer[i].custName); printf("Phone Number: %s \n", customer[i].custTel); printf("Order Type: %s \n", customer[i].orderType); printf("Order Menu: %s \n", customer[i].orderMenu); printf("Order Unit : %d \n", customer[i].orderUnit); printf("Mode Purchase: %c \n", customer[i].modePurchase); printf("Total Price: %f \n", customer[i].totalPrice); printf("\n"); } } int main() { struct custInfo customer[3]; readData(customer); calculatePrice(customer); sales(customer); return 0; }
Anonymous
I don't know why, the loop inside of my calculatePrice() can't be returned. I tried and the output did not read the TotalPrice. :/
Anonymous
I don't know why, the loop inside of my calculatePrice() can't be returned. I tried and the output did not read the TotalPrice. :/
Are the strings matching correctly? In pure C case-sensitive string matches go like: if(!strcmp(str, "abc")) ..., strcmp returns zero when both args have the same chars.
Anonymous
Some languages let you compare with an operator (==) and some want you to use a function or method.
Anonymous
The nested if statements are a bit hard to follow... Of course real-world business logic can be convoluted as well.
Anonymous
Thank you :)
Anonymous
#include <stdio.h> #include <string.h> struct custInfo { char custName[30]; char custTel[20]; char orderType[20]; char orderMenu[30]; int orderUnit; char modePurchase; float totalPrice; } customer[3]; struct custInfo readData(struct custInfo customer[3]) { int i; for(i=0; i<3; i++) { printf("Enter Name: "); scanf(" %[^\n]", customer[i].custName); printf("Enter Phone Number: "); scanf("%s", customer[i].custTel); printf("Enter Order Type: "); scanf("%s", customer[i].orderType); printf("Enter Order Menu: "); scanf(" %[^\n]", customer[i].orderMenu); printf("Enter Order Unit: "); scanf("%d", &customer[i].orderUnit); printf("Enter Mode Purchase: "); scanf(" %c", &customer[i].modePurchase); printf("\n"); } return customer[i]; } struct custInfo calculatePrice(struct custInfo customer[3]) { int i; customer[i].totalPrice = 0.0; for(i=0; i<3; i++) { if(strcmp(customer[i].orderType, "broiler") == 0) { customer[i].totalPrice = 30.00 * customer[i].orderUnit; } else if(strcmp(customer[i].orderType, "fryer") == 0) { customer[i].totalPrice = 10.00 * customer[i].orderUnit; } } return customer[i]; } struct custInfo sales(struct custInfo customer[3]) { int i=0; for(i=0; i<3; i++) { printf("Name: %s\n", customer[i].custName); printf("Telephone Number: %s\n", customer[i].custTel); printf("Order Type: %s\n", customer[i].orderType); printf("Order Menu: %s\n", customer[i].orderMenu); printf("Order Unit: %d\n", customer[i].orderUnit); printf("Mode Purchase: %c\n", customer[i].modePurchase); printf("Total Price: %f\n", customer[i].totalPrice); printf("\n"); } return customer[i]; } int main() { struct custInfo customer[3]; readData(customer); calculatePrice(customer); sales(customer); return 0; }
Anonymous
I tried and it still not working
Anonymous
the loop inside of my calculatePrice() still can't be read. The output did not read the TotalPrice
Anonymous
the loop inside of my calculatePrice() still can't be read. The output did not read the TotalPrice
I think after printf("Enter Mode Purchase: "); it might be reading a newline instead of a letter... Input is inherently tricky! #include <stdio.h> #include <string.h> #include <ctype.h> char* readln(int sz, char *buf) { char *str = fgets(buf, sz-1, stdin); if(!str) return NULL; while(isspace(*str)) str++; int len = strlen(str); if(len == 0) return str; while(isspace(str[len-1])) { str[len-1] = '\0'; len--; } return str; } int str2buf(char *str, int sz, char *buf) { return snprintf(buf, sz-1, "%s", str); } int str2char(char *str, char *c) { if(!str) return 0; else *c = str[0]; return 1; } int str2num(char *str, int *num) { return sscanf(str, "%d", num); }
Abid
Could anyone send link for eclipes dowonload please
Igor🇺🇦
Bharti
Hey...im a beginner in c.. please tell me a program for swapping of two numbers without using a third variable
Igor🇺🇦
Hey...im a beginner in c.. please tell me a program for swapping of two numbers without using a third variable
Did you even try to search for yourself? 🤦‍♂️ https://www.ecosia.org/search?q=swapping+of+two+numbers+without+using+a+third+variable
Renuga
#include <stdio.h> void displayMovielist(); struct Movies { char mname[50]; int duration; char language[10]; char genre[20]; float price; char showtime[3][100]; }; struct Movies movie_1={"AQUAMAN",126,"ENGLISH","ADVENTURE",16.00,{"10:45AM","03:35PM","10:50PM"}}; struct Movies movie_2={"THE AVENGERS",130,"ENGLISH","FANTASY",16.00,{"01:40PM","04:30PM","10:10PM"}}; struct Movies movie_3={"UNCHARTED",120,"ENGLISH","ACTION",12.00,{"11:35AM","03:50PM","10:15PM"}}; struct Movies movie_4={"CINDERELLA",120,"ENGLISH","MUSICAL",12.00,{"11:10AM","02:40PM","08:00PM"}}; struct Movies movie_5={"POLIS EVO",160,"MALAY","ACTION",12.00,{"01:40PM","04:30PM","10:10PM"}}; int main() { displayMovielist(); return 0; } void displayMovielist(struct Movies[]) { system("cls"); printf("\n\n"); printf("\t\t\t\t=================_List Movie_==================\n\n\n"); printf("\t\t\t\t[1] => %s\n",movie_1.mname); printf("\t\t\t\tDuration => %d\n",movie_1.duration); printf("\t\t\t\tLanguage => %s\n",movie_1.language); printf("\t\t\t\tGenre => %s\n",movie_1.genre); printf("\t\t\t\tTime => [1]%s \t [2]%s \t [3]%s\n",movie_1.showtime[0],movie_1.showtime[1],movie_1.showtime[2]); printf("\t\t\t\t[1] => %s\n",movie_2.mname); printf("\t\t\t\tDuration => %d\n",movie_2.duration); printf("\t\t\t\tLanguage => %s\n",movie_2.language); printf("\t\t\t\tGenre => %s\n",movie_2.genre); printf("\t\t\t\tTime => [1]%s \t [2]%s \t [3]%s\n",movie_2.showtime[0],movie_2.showtime[1],movie_2.showtime[2]); printf("\t\t\t\t[1] => %s\n",movie_3.mname); printf("\t\t\t\tDuration => %d\n",movie_3.duration); printf("\t\t\t\tLanguage => %s\n",movie_3.language); printf("\t\t\t\tGenre => %s\n",movie_3.genre); printf("\t\t\t\tTime => [1]%s \t [2]%s \t [3]%s\n",movie_3.showtime[0],movie_3.showtime[1],movie_3.showtime[2]); printf("\t\t\t\t[1] => %s\n",movie_4.mname); printf("\t\t\t\tDuration => %d\n",movie_4.duration); printf("\t\t\t\tLanguage => %s\n",movie_4.language); printf("\t\t\t\tGenre => %s\n",movie_4.genre); printf("\t\t\t\tTime => [1]%s \t [2]%s \t [3]%s\n",movie_4.showtime[0],movie_4.showtime[1],movie_4.showtime[2]); printf("\t\t\t\t[1] => %s\n",movie_5.mname); printf("\t\t\t\tDuration => %d\n",movie_5.duration); printf("\t\t\t\tLanguage => %s\n",movie_5.language); printf("\t\t\t\tGenre => %s\n",movie_5.genre); printf("\t\t\t\tTime => [1]%s \t [2]%s \t [3]%s\n",movie_5.showtime[0],movie_5.showtime[1],movie_5.showtime[2]); }
Renuga
i have a error at the bold one
Renuga
void displayMovielist(struct Movies[])......................in this.............it is saying that error: parameter name omitted
Renuga
i dnt knw whts the problem😭😭😭
Anonymous
i dnt knw whts the problem😭😭😭
The function declaration args changed, and one version only compiles with C2x. You probably want a function that prints one at a time. void displayMovie(int index, struct Movie mv) { ... } and then displayMovie(1, movie_1); displayMovie(2, movie_2); displayMovie(3, movie_3);
CΞMİL
h
CΞMİL
hi
Lucas
Could anyone help my exam (Algorithms and programming 2 in C programming language) please?
Anonymous
Rational Rose
Anonymous
Hi can someone will help me in C++Assignment?
Anonymous
Hi can someone will help me in C++Assignment?
Show the code, explain what's it about, where is the error, etc.
#
Google it
I don't have soo much of time😒
Anonymous
I don't have soo much of time😒
yet you're typing here anyway
Anonymous
when you could have just typed in google
CΞMİL
Omkar77
Which is better IDE for c++ VSC or codelite ?
Bruno
/get ides
Omkar77
Ah thanks
Anonymous
Hi guys, can anyone suggest an easy text based game to do in C? Something that uses loops and maybe arrays.. its for our finals 🤭
Anonymous
when you could have just typed in google
No need of your explanation 😏😏
Anonymous
Who asked to you?
you asked for everyone in the group a dumb question
Anonymous
the only thing you deserve is an equally dumb answer
Anonymous
shhhh dummy
Anonymous
shhhh dummy
You look a mad person
Anonymous
go learn to use google
Anonymous
you need it
Anonymous
Anonymous
Ok
Xudoyberdi
#offtopic
Anonymous
go learn to use google
btw, #1 free advice right here for all of you learning to program
Anonymous
🤣🤣
Anonymous
No need of advice from a mad
sure sure script kiddie
Anonymous
sure sure script kiddie
You need to do suicide🤣🤣
Anonymous
Continue your conversations in the offtopic group
Anonymous
Why report
Anonymous
No reason reason for report
Anonymous
Report yourself
Xudoyberdi
Finally, relief came.
Omkar77
For windows visual studio or visual studio code ?
Omkar77
Lmao gg XD
Anonymous
any one help me
Omkar77
any one help me
Explain ur help