V
there is also warning and task's instruction in pastebin too
Ammar
hi guys, could you help me with codewars 4 kyu? I've done with it, but I have 1 warning because of compiler I guess. I was trying to google that warning, but only found suggestion about "return 0" in main() function (codewars have no main() in yourself tasks :\) and something about -Wall (codewars have no possibility to setup compiler args too :\). Code is here: https://pastebin.com/mdXFnQYA and yeah, code is a bit strange because that task requires to not use function like stoi, atoi or boost, so I had to write function like this
This warning means a function with return type has a possibility not to end with return statement. Simpler code to reproduce the warning. int f(int a) { if (a == 5) { return 1; } } That code will be undefined behavior if you give the argument with a != 5. Because it ends with no return statement. To fix that, you have to make your function always reaches return statement for any given condition.
Ammar
Your switch case does not have "default".
V
@ammarfaizi2 yup, I've already fixed it with default: return -1; , but problem was in for in convert_to_int and program was crashing because of segfault that I've also fixed. But thank you anyway
Ammar
@ammarfaizi2 yup, I've already fixed it with default: return -1; , but problem was in for in convert_to_int and program was crashing because of segfault that I've also fixed. But thank you anyway
Nice. One more tips, to convert ASCII to integer, you don't have to use switch case like that. You can just subtract it with 48. For example: '0' - 48 = 0 '1' - 48 = 1 '2' - 48 = 2 ... and so on
V
@ammarfaizi2 wow, it's useful and it makes code shorter, thanks
Anonymous
Hello Everyone I'm new to this group, so I think an introduction will help; My name is Grace from Somewhere in West Africa. I'm interested in internet and Tech, I love biotech, programming, and software development and security So feel free to network and most importantly, have a nice day 🤗
cryptpi
have you any roadmap for C/C++ ?
cryptpi
like a cheatsheet roadmap
Konstantin
have you any roadmap for C/C++ ?
Are you looking for something like this ? http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0592r4.html
Hidd3N
Could anyone please explain me why value of x is 9 and value of y is 10 even though the memory address is same for both
Hidd3N
Optimization? X is marked as just const, not volatile.
Okay let me just check with volatile then.
Hidd3N
Yeah volatile fixed the issue
Nils
I'm a completely beginner with programming I want to know, your personal opinion about it and if you can tell me how to became better
Practice, lot. And always try new stuff. When you're bored you are doing something wrong.
Anonymous
Well
M.Khorram
/warn screen photo
Hi, I think that warning and banning is not required in most cases. And applying strict rules is not productive
M.Khorram
/warn screen photo
Please think about more tolerant rules
Anonymous
Idiots who can't read should obviously not code
Anonymous
It is right to ban them for the good of the world
Soham
Hi Guys, can you suggest me some resources to get started with C/C++?
Anonymous
Unless somebody throws $100 an hour in your face for doing it
Soham
Avoid C++
Ok, may I know the reason as well?
ɴꙩᴍᴀᴅ
Ok, may I know the reason as well?
you don't want to hit your face against a brick wall...
Soham
Ok, then maybe resources for c?
ɴꙩᴍᴀᴅ
The K&R book is a nice start
Soham
The K&R book is a nice start
Not sure but do you mean kernigan and ritchie?
ɴꙩᴍᴀᴅ
Not sure but do you mean kernigan and ritchie?
Yeah, that book, the white bg with a blue C in the middle one🙃
ɴꙩᴍᴀᴅ
Maybe? https://stackoverflow.com/questions/33020791/cant-we-initialize-automatic-array-variables#33020926
Nisal
#include <stdio.h> #include <stdlib.h> //Global Variable char *choice[],ele[20]; int i; int size; //Creating Stack struct stack{ int arr[100]; int top; int rear; }st; //Inserting Element void push(int element) { if((st.top)==size) { printf("\n Stack is Full"); } else { st.top--; printf("\nEnter a Value "); scanf("%s",ele); st.arr[st.top]= ele[]; } } //Removing Element int pop() { if((st.top)==-1) { printf("\nStack is Empty"); } else { int out; out=st.arr[st.top]; st.top++; return out; } } //Peek int peek() { int display; display=st.arr[st.rear]; return display; } //Display Stack void display() { if((st.top)>=0) { printf("\n\nElements in the Stack"); for(i=st.top;i>=0;i++) { printf("\n%d",st.arr[i]); } } else { printf("No elements to Display"); } } int main() { st.top=-1; printf("Enter a Stack size less than 100 : "); scanf("%d",&size); printf("\nStack Operations....."); printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.PEEK\n\t 4.DISPLAY\n\t 5.EXIT"); do{ printf("\nEnter Your Choice "); scanf("%s",choice); switch(choice[]) { case 1: { push(ele[]);break; } case 2: { printf("%d",pop()); } case 3: { printf("%d",peek()); } case 4: { display();break; } case 5: { printf("\n\t EXIT Point");break; } default: printf("\nEnter a correct choice (1,2,3,4,5)"); } }while(choice=5); return 0; }
Nisal
Nisal
With this code
Ammar
Can some one help me
What to do? You should explain first, what do you need?
Nisal
Nisal
What to do? You should explain first, what do you need?
Yh its good after explaining and fix this
Ammar
You forgot the index.
Nisal
So how I make that correct
Nisal
Can you share the corrected code
Nisal
But still I don’t know how to apply
Ammar
But still I don’t know how to apply
I am not really interested in your problem. But here, the correct way to access the element of array is like this. For example: int arr[] = {1,2,3,4}; You want to access 3rd index, use can use: arr[2]; You can use another variable to dynamically access n-th index: int i = 2; arr[i]; /* do something with 3rd index. */
Ammar
#include <stdio.h> #include <stdlib.h> //Global Variable char *choice[],ele[20]; int i; int size; //Creating Stack struct stack{ int arr[100]; int top; int rear; }st; //Inserting Element void push(int element) { if((st.top)==size) { printf("\n Stack is Full"); } else { st.top--; printf("\nEnter a Value "); scanf("%s",ele); st.arr[st.top]= ele[]; } } //Removing Element int pop() { if((st.top)==-1) { printf("\nStack is Empty"); } else { int out; out=st.arr[st.top]; st.top++; return out; } } //Peek int peek() { int display; display=st.arr[st.rear]; return display; } //Display Stack void display() { if((st.top)>=0) { printf("\n\nElements in the Stack"); for(i=st.top;i>=0;i++) { printf("\n%d",st.arr[i]); } } else { printf("No elements to Display"); } } int main() { st.top=-1; printf("Enter a Stack size less than 100 : "); scanf("%d",&size); printf("\nStack Operations....."); printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.PEEK\n\t 4.DISPLAY\n\t 5.EXIT"); do{ printf("\nEnter Your Choice "); scanf("%s",choice); switch(choice[]) { case 1: { push(ele[]);break; } case 2: { printf("%d",pop()); } case 3: { printf("%d",peek()); } case 4: { display();break; } case 5: { printf("\n\t EXIT Point");break; } default: printf("\nEnter a correct choice (1,2,3,4,5)"); } }while(choice=5); return 0; }
I think you should learn the basic first, before making this great program. Don't skip the fundamental of C/C++ programming.
Nisal
Thanks
Ammar
Ok 👍
Nisal
I’m only getting a warning now rest of the things I finished
Anonymous
A stack program is at best a 2-liner
Anonymous
4 in the worst case
Anonymous
Hello guys, is there a cross-platform buildsystem that supports c++20 modules?
Anonymous
It seems that build2 doesn't support it very well.
Nisal
This is the only warning now I’m getting
Nisal
Rest of the things I fixed
Ammar
Your pop function may not end with return statement. You have to make it always ends with return statement for any given condition.
Nisal
Thanks I fixed that one thanks for the help👊 @AlrightNoyes
Nisal
In this one I couldn’t fix in the printf part
Nisal
At the end of the code
V01D
Please learn C
Nisal
V01D
You are using %s on an int array
Nisal
Omg thanks bro
Nisal
👊
Nisal
Now I saw that
Ammar
Also the l variable is not declared on that scope.
Ammar
Where is your l variable?
Anonymous
Also it won’t work because you decresing m
V01D
Debugger time
Nisal
Thanks for the help
Anonymous
You using uninitialised variable for accessing array
V01D
You using uninitialised variable for accessing array
Do the different data types matter? char = int array?
Nisal
I don’t how to use bool in two ways that’s why I use only false
Ammar
Line 28, you use l to access the element of array. Yet l is uninitialized (is not given a value).