Mysterious extra text in style check [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am working on CS50's Runoff problem in Problem Set 3, and the program is working when I run it. When I run the check program, however, it notes one particular function as being wrong entirely despite it working when I run the program manually. When I run the style check program to make sure there is no excess whitespace, etc; the results show extra text where there is none in the program.
In both of the screenshots I have the function returning the error in the top window.
Any ideas what is causing the mystery text, or the 4 errors? If it s more helpful, I can paste the entirety of the code here.
Thank you!

Do not be distracted by style50. Any style issues should never change the results of the program. The program is failing check50 because of functional deficiencies. The spec for print_winner says:
If any candidate has more than half of the vote, their name should be printed to stdout and the function should return true.
"More than half the vote" depends on the number of voters not the number of candidates. Try an election with 3 candidates a, b, c with 7 voters who vote b,b,b,b,a,a,c. Who wins? (b). What result does program return?
Deal with style issues after program passes check50 and before submit50. (But it's good practice to double check check50 results after cleaning up style, lest a bug creep in :)

Related

.exe doesn't close properly in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am a beginner in C, I wrote a code to calculate the average of grades, it's fairly simple, but it won't close properly when I run it in the .exe. I'll attach a video showing how it works, first I run it from the code, then from the .exe.
Video
Whatever the IDE is you're using, it is using a runner.exe to wrap the execution of your program and show you that "program stopped, hit any key" sort of prompt.
That doesn't happen for a compiled program, and the console window is closed right away at your exit(-1) call.
If you want to see the final output of your program, run it via the command prompt.
You can use exit(0) instead of exit(-1).

Count amount of words, characters, newlines in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know it is not recommended to post code as an image, since I am getting a formatting error when trying to post code on here. Anyway, I am trying to write a simple C program to count number of words, characters, newlines using do while loop. However, the output is not as expected. Please help!
Instead of a do-while, you should try using while. Since your code starts off by checking whether a is any of your if cases, it goes to the else case, and increments the New line variable. If possible, could you share the output screen.

C objective something wrong with if statement [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
This code written in c objective with Visual Studio
Today a friend of mine sent this code. In university they tried to make a grade calculation program. The problem is when you write -0 to input and press enter it gives result as the last if statement regardless the if statement is.
Same conclusion appears when you write +0 etc.
Why this is happening any ideas? Thanks in advance.
The concept of negative zero doesn't exist in the C language (and all other languages I'm aware of).
So if you enter 0, the expression grade == -0 will be true and therefore your program will display Zero can not be negative.

Converting a character into a space in C arrays [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So lets say I have received a message that resembles the following
"L2N5*8R10!11T0A1K3Y14#4W7O6O9C12R13"
and I am expected to sort out the characters in accordance to the numbers succeeding them and change the characters that are not letters into a space. I have no problem doing the sorting out part, I am only having a trouble while trying to write a function that will change those characters into space.
The out put should be something like this
TALK NOW OR CRY
but I am getting
TALK#NOW*OR!CRY
Can anyone help me figure out what my function should look like so that I can be able to change the characters into space??
Unless you show your code, we'll only be able to guess!!
However, as a general suggestion, I would recommended, you should check each entry against isalpha(). In case you got a return value of 0, replace the entry with a .

What are ways a debug statement could "fix" bugs in a program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In a recent interview, I was asked the following question:
You have a bug in your program, after attempting to debug it by inserting statements like printf, console.log, System.out.println, echo, etc, the bug disappears. How can this happen?
I responded with answers like the following:
You have something with side effects in the print statement, eg: System.out.println(foo.somethingWithSideEffects())
Adding printf changes the memory layout of the program, therefore it could cover adjacent memory and prevent crashes
Undefined Behavior in native code (like uninitialized values, buffer overruns, sequence points, etc)
The interviewer said those aren't the only ways that this could happen, and I couldn't think of any other ways simply adding a printf, etc could "fix" a bug in a program.
What other things could cause this to happen?
The biggest thing that comes to mind is that putting debugging code in can change the timing of the code, which can matter if there is a race condition in the code being debugged. It can be very frustrating to try to debug race conditions that disappear when inspected like this.
That could be happen because of memory overflowing , or there could be system interrupt while the program running.If you cannot really attach the debug so you may write eventlogs but it should be the last way to do i think

Resources