22
u/wsppan Sep 23 '20
What am I doing wrong?
You are posting your code as an image
Your title is vague
You are not including if or what your warnings, errors, desired or actual output are.
Try compiling from the command line with all warnings. i.e.
gcc -Wall -Wextra -o myfile myfile.cOr find out how to do that in your IDE.
11
Sep 23 '20
I'm starting to wonder if people know how to take screenshots with their OS...
12
0
Sep 23 '20
[deleted]
2
Sep 23 '20
Haha, thanks for the chuckle. Had to use VNC through a couple jump hosts at work... been a pain.
8
7
u/IamImposter Sep 23 '20 edited Sep 23 '20
Here are a few suggestions:
some of us are on mobile. It is easier to read text as compared to images.
if I wanna try and compile your code, I can just copy-paste it in my editor, if it's in text form. Some of us are too lazy to type the whole thing by ourselves.
when you get an error, copy-paste it into google. Google is programmer's best friend. Learn to use it.
if error is something like - declaration for function xyz not found, google "xyz + header file". You'll get some useful answers. Looking for information and extracting something useful out of it is another skill that we programmers need.
Now I see squiggly under scanf_s and I see that you are using a%c.
Function with _s are safe functions ie they take buffer size for character and string types. So you need to pass size if character variable ie 1.
scanf_s("%d%c%d", &num1, &ch, 1 &num2) ;See 1 after ch. That tells it that there is space to read only 1 character in ch variable.
See if that helps.
1
Sep 23 '20
Green squiggles are like a compiler warning. There is something about the code it doesn't like but it compiles. Could be unrelated to your lack of answer, too.
Tip: do your work on the command line. Compile with gcc -Wall -g foo.c -o foo for useful compiler warnings and even better, you can step through your code line-by-line with gdb.
Visual Studio (or any IDE for that matter) are not good for learning a new language.
1
1
u/GregSilverblue Sep 25 '20 edited Sep 25 '20
Holi shit bro, I remember myself a couple years ago when I was still learning C writing almost exact code as you are. I guess we all begin with the same shit.
Your fucking braces after if and else are missing, how the hell you forget that.
Btw, you don't have to write if(opok == 1) you can just write if(opok) And it will execute if op is 1. 1 acts like boolean in c.
0
0
Sep 23 '20
[deleted]
1
u/cakes1234567 Sep 23 '20
It finds it, it told me to use scanf_s instead of scanf
0
Sep 23 '20
[deleted]
1
u/cakes1234567 Sep 23 '20
It dosent compile
0
Sep 23 '20
[deleted]
1
u/cakes1234567 Sep 23 '20
C4996 when i use scanf
0
Sep 23 '20
[deleted]
-4
5
u/FlavorfulArtichoke Sep 23 '20
please:
I) formulate a question properly,
II) explicitly show the code (formatted here with reddit, instead of a picture)
III) show what is the error and how to reproduce it.
There's no error from the output, but from what we can see in the poorly taken picture, `scanf_s`'s header is not included. Try to add `#include <stdio.h>` to the beginning of the file