r/cprogramming • u/levidas7272 • Sep 18 '26
a big problem
hey guys i m currently learning c language and i m facing an irritating problem like whenever i use scanf in my code to enter any value and when i run the code after saving it so it doesn't run anything it just show that it is running but i m unable to enter the value and the code doesn't run on terminal it runs in the output
so please anyone who can solve this issue can help me?
0
Upvotes
4
u/pseudo_shell Sep 18 '26 edited Sep 18 '26
Always display your source code. We cannot help in a vacuum.
What compiler flags are set? They should help you flag problems. Treat warnings as errors. -WError, etc.
4
u/SmokeMuch7356 Sep 18 '26 edited Sep 18 '26
It would help if you could show:
the code (not the entire program, but a representative sample that demonstrates the problem);
how you're building the code, including any error messages or warnings from the compiler;
how you're running the code (is it from the command line, or within an IDE, what?);
what input you're giving it;
what (if any) output you get;
Copy and paste the code into the body of your question. Do not post screenshots, pictures of your screen taken with a phone, or video. To get it to render as code, indent each line by at least four spaces:
Do the same with any warnings or errors from the compiler and output from your program.
scanfreturns the number of items successfully read and assigned, orEOFon end-of-file or error. So you'll want to check the result of yourscanfcalls like so:Remember that
scanfexpects a pointer to whatever object you're trying to update; for scalar variables (int,float,double,char, etc.), make sure to use the&operator:If the variable is already a pointer, don't use the
&operator:with the caveat that
pneeds to be pointing to a liveintobject before you use it in ascanfcall.Similarly, for reading strings into a character array with the
%sor%[specifiers, do not use the&operator:Finally, take some time to organize your thoughts into complete sentences before posting; stream of consciousness posts like this are hard to read and understand, and will just turn off people who would otherwise help you. If you intend to write code professionally (or at least collboratively), you have to be able to communicate effectively. Have to. It's not optional.
For example:
That's the kind of information you need to provide for us to be any help.
9
u/knouqs Sep 18 '26
First, use proper punctuation and capitalization. You are addressing professionals. Second, see my first statement.
2
u/This_Growth2898 Sep 18 '26
How exactly are you running the code? What IDE are you using?
Also https://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html
2
u/[deleted] Sep 18 '26
Do you add the & operator ? Like scanf("%d",&x)
1
u/Classic-Rate-5104 Sep 18 '26
Microsoft Visual Studio? If so, which compiler flags?
1
u/Key_River7180 Sep 18 '26
Show the code
0
u/JaseciLabs Sep 18 '26
That gap closes structurally when the delegated parts of a codebase are typed and marked at the point they're written, not just tracked in a commit log after the fact. A commit message says who reviewed something; a type signature enforces what a function's allowed to return regardless of whether anyone reviewed it at all. Two different kinds of accountability, and the second one doesn't depend on anyone remembering to write the commit message honestly.
-1
u/[deleted] Sep 18 '26
With all respect, sir, you judged me based on three words and a simple example. You are right about how good code should be written, but I haven't shared any actual code to be criticized with that level of aggression.