r/C_Programming • u/Either-Suggestion400 • Aug 16 '26
How do I solve problems without using AI
Hello guys. I am attempting to learn how to code again but without the use of AI this time.
How do you attempt a problem or understand a solution without using AI for help.
For example, I wanted to build a small calculator to remind myself of the basics of C. I had a problem where my scanf was not outputting the desired result.
The program had something like this:
int x, y;
printf("Enter two operators: ");
scanf("%d", &x);
scanf("%d", &y);
printf("x: %d, y: %d", x, y);My inputs would be 10 & maybe 2, but the output would be 10 & 0, in some cases 0 and nothing for y.
I was able to get through this by just using one scanf:
scanf(“%lf %lf”, &x, &y);
But I still do not understand why that happened and through my google search, could not find anything that explained it well. The problem might also be that I cannot explain the problems I come across clearly, so I might not be able to find an answer through google.
So my question is, how do you guys go through problems like these where you can’t find a post where someone had a similar problem and had been told what to do to solve the problem without defaulting to AI.
Excuse my writing - I am trying to learn how to type without letting AI revise my sentences.
16
u/zhivago Aug 16 '26
The first thing to do is to read the documentation for scanf.
lf you do this you will see that it returns a meaningful value.
Check this value to see if has a surprising value.
lf so read and test theories until the value is no longer surprising.
Rinse and repeat.
Always work on the first surprise.
When there are no surprises you understand.
Good luck.
18
u/heneriss Aug 16 '26
Search on the internet, reddit, stackoverflow and any forums you are on.
By reading explanations written by other people I get to grasp something much better than asking AI and getting an answer that I probably forget the next hour.
6
u/Irverter Aug 16 '26
Congratulations on trying to not depend on AI!
For any programming problem, the resources to go to are the documentation of what you're attempting to use (scanf in this case), an example of how to use it if available, and whatever stackoverflow question/forum/blog post related to the issue. The solution may be clearly written on any of those, or you'll have to figure out a solution from the info available.
Problem solving is a skill that takes time and effor to develop. Don't give up!
And as you clearly identified, part of problem solving is communicating what the problem is. A lot of projects use something like this for their issue reports:
And to help you and whoever tries to help you, be aware of the XY Problem and always avoid it.
11
u/silvertank00 Aug 16 '26
man scanf would help, or a book.
5
u/PittLeElder Aug 16 '26
Go to cpp reference and just read. https://en.cppreference.com/c/io/fscanf
In this case it even has the exact example of the thing you were struggling with described.
3
u/easedownripley Aug 16 '26
The main thing for you is that you've got to keep digging. I promise there are extensive posts and information about scanf and all the weird problems that it can have. If you didn't find someone talking about it, it's likely that you just gave up too soon.
3
u/pfp-disciple Aug 16 '26
For many problems, including what you described, finding thorough documentation is very useful. In Linux, the man pages are great. For any system, cppreferece.com is great, don't let the "cpp" bother you - it has an entire portion dedicated to C.
In your example, you'd find the docs for
scanfand see how it handles whitespace and line endings.2
u/ApeironThanatos Aug 16 '26
I commend you for making the effort to learn. Everyone else is right: man pages, forums, books, etc. What I think is missing from these explanations, and missing from using AI, is learning how to solve problems. Your example is fairly straightforward, and you will likely find a direct explanation of the issue and resolution. However, this becomes rarer and rarer as you solve harder and more complex issues. The skill you are practicing is not necessarily memorizing all the permutations of how scanf works, but how to take information and adapt it to a problem. This takes practice and understanding that comes with time and experience. As a contrived example, maybe you read on some forum about an issue someone had with printf and how they solved it, and that inspires you to adapt that solution for scanf. As your understanding grows, you’ll get better and better at adapting different problems to different solutions.
Just keep reading, keep learning and keep practicing. It will get easier, if you stick with it.
Where AI can help here is explanation. Don’t have AI spit out some code and then move on. In fact, prompt the AI to generate no code at all. Have it guide you to an answer, through questions and explanations. Engage with it as something that can help answer a question, but then implement that explanation yourself. Ask the AI “why”, not “how”.
2
u/HalifaxRoad Aug 16 '26
If you are using someone elses library read the documentation.
Trouble shooting if isolating a problem goes a long ways, figure out what parts of the code are working and what isnt working
Another trap I think newbies fall into is writing too much code at once. Write each piece and test as you go. Feed in a few cases into your functions to make sure you have all your bases covered. On paper it takes a bit longer to write code this way, but you will spend so much less time debugging!
Really get stuck, someone else has probably had the same problem as you on stack overflow.
Sometimes its good for your brain to be really stuck, its uncomfortable in the moment, but you can be driving home from work and just be lost in the code in your head and BAM, thats where the problem is! Ive turned around and gone back to work to see if that was the fix before...
2
u/WonderfulTill4504 Aug 16 '26
Wow. I can believe than this thread is a real issue but it seems it is.
So without falling on the trap of being sarcastic just go a buy a book, cheap this days, about leaning C. Seriously, take your thumb out of your ass and then go page by page following the explanations and exercises.
You will then realize than you are not as stupid as you think you were or other told you are.
Then pick online courses from universities. Many prestigious universities have courses online with the syllabus, for free.
Do not watch video tutorials. Take your pace to learn.
How do you know you learn something? When you can explain it to others using your own words. Now you own that piece of knowledge.
3
u/ApprehensiveBrain173 Aug 16 '26
Read a book. I'm pretty new to C myself and im learning off books, forums and if i want explore concepts for e.g. alot of C books will tell you about the compiler but not what a compiler actually consists of and how it works in depth i may use AI to gather a little more info on something like this.
To help though heres a simple explanation of why your code likely wasnt working: It was probably your input. If you input 10, 2 for your first program the scanf("%d", &x) reads 10 then stops at the comma leaving it stuck in the input buffer so when u get round to ("%d", &y) its going to read , and throw an error in 0 as y is unassigned. If you just input it as 10 2 it would work fine as you would have 2 load into the buffer instead of the comma. You can do this with either a simple space or use the enter key on a new line. Hope this helps a little!
3
u/Snufflleupagus27 Aug 16 '26
I use geeksforgeeks and w3 schools a lot. One of my old bosses once told me its important to become good at sleuthing. Keep doing small projects consistently it will start to click for you.
4
u/SmokeMuch7356 Aug 16 '26
There had better be an implied /s in this post, because if not, holy crap.
How do you solve problems without using AI? By using your own intelligence.
Multiple generations of programmers learned their trade without AI. A good chunk of us learned without the Web. We used books, man pages, user groups, etc.
Check the links under "Resources" in the sidebar to the right.
1
u/Bugodi21 Aug 16 '26
This is satire ?
1
u/Afraid-Locksmith6566 Aug 16 '26
the same way you would do it for last 80-ish years of computer science. you sit down, analyze the problem, read some books, manuals, stack overflow, documentation.
2
u/detroitmatt Aug 16 '26
basically any time you have behavior being unpredictable and getting garbage values like this, it's because somewhere in your program you have accidentally written undefined behavior. So, what you should do then is google "undefined behavior scanf" (or whatever part of the program is the least familiar to you). learning to intuit what is a likely problem spot comes with experience.
2
u/Daveinatx Aug 16 '26
Your brain is a muscle, it strengthens through thought and reading.
2
u/TheOtherBorgCube Aug 17 '26
The operative word being "something".
If you paraphrase your code with what you half remember, you're going to get vague answers.
Not with the program you posted you wouldn't.
Just changing the
scanfformat without declaring the variable types todoublewouldn't work.Lesson 1 - Always compile with all warnings enabled, and pay attention to what they say.
Lesson 2 - If you ignore lesson 1, then your program will do all sorts of weird things, including seeming to work regardless of your attempts to make a mess of it.
Like this is what I get when I just change the
scanfformat without changing the variable type, or theprintfformat.So yeah, nothing mysterious about getting weird output if you're not consistent with the variable types and the formats.
Also, just one
scanfisn't the fix, it was changing the format string.All these are equivalent.
Nor does it matter whether you enter both numbers on one line
or on separate lines (because newline counts as whitespace)
2
u/ImANoobAtLife7 Aug 16 '26
Hmmm you can setup your AI to not give you an answer and instead nudge you while you share your thinking.
Tap into your intuition and explore different paths and have it assist you when you need a hint.
AI is underrated as a learning tool.
1
u/realhumanuser16234 Aug 16 '26
Read the C standard. It's very easy to read and relying on secondary sources for such simple matters is just introducing room for error.
1
u/onearmedphil Aug 16 '26
I am also learning c without ai (with the exception of me showing ai my train of thought that I am having trouble understanding and having it confirm if I am right or wrong - like a teacher).
I would search noai.duckduckgo.com for scanf examples, then review how their examples were different than mine. I would then tweak my code to match theirs a bit until an outcome changes. Then I’d try to understand the outcome.
I have been reading head first c oreilly. I really like it and it solves a lot of back and forth with Google because I can either reference it or I’ve already read about it and understand scanf more than just guessing.
1
u/mykesx Aug 16 '26
FWIW, I don't remember ever using scanf in the last 30+ years. I learned how to parse strings early on and process input that way.
So some gets() variant along with strptok() and atoi(), etc.
Use man to read up on those.
I didn't have AI all along, so I ended up learning and retaining what I learned. Many techniques are muscle memory now.
1
u/[deleted] Aug 24 '26
Be ready to fail a lot at solving problems and not give in to using ai!
1
u/Blitzbasher Aug 16 '26
Try scanf("%d %d", &x, &y);
As for the AI thing, you hit up 1-800-GOOGLE like a caveman. Seriously though AI is a tool, a tool that you must constantly be asking yourself if you understand the solutions it gave you.
-4
u/Bitter_Care1887 Aug 16 '26
Train a small model on Man pages and and query it..
Try reframing on what exactly and why you are trying to avoid AI, otherwise it becomes an Anti-AI fetishism..
-7
u/Run-OpenBSD Aug 16 '26
You realize that asking us on reddit is the same as asking ai but with people.
38
u/[deleted] Aug 16 '26
[removed] — view removed comment
1
u/[deleted] Aug 16 '26
[removed] — view removed comment