My program suddenly stopped working when I added a new function [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 days ago.
This post was edited and submitted for review yesterday and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I was using the function space_char to look for spaces and give a 1 if there is a space and a 0 if there is no space. The program was working fine until I added a non_space_char function which just ruined the whole program. The non_space_char function does the opposite of space_char which is return a 1 if no spaces and 0 if there is a space. I turned the non_space_char into comments to return the program to its original state but it remains broken. What did I do wrong?
Code without comments for non_space_char how I have it right now.
What I mean by the program is broken is that instead of giving me either space or no space it only shows no space as the answer to both functions. For example if I put for input "hello world" it would put there are no spaces for each function. Before I added the non_space_char function I would receive
"There is a space" for the space_char function with the same text "Hello World".

Related

Mysterious extra text in style check [closed]

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 :)

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.

How printf() function in c actually works? [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 4 years ago.
Improve this question
We all know that printf() is a function of <stdio.h>.
I want to know that what's happening under the hood when we type printf("something"); and it gets displayed on the screen... How come it's displayed on the screen and what is the code inside printf() function by which it displays something on the screen?thanks in advance
printf("something"); is the equivalent of fprintf(stdout, "something"); so it prints on the standard output, whatever where finally the output will be done (screen, file, pipe, ...)
because "something" doesn't content special formating (using %) if is printed unchanged, and probably your question moves to be how putchar() / fputc() works
printf doesn't know what a screen / file / pipe / ... is, in the same way scanf doesn't know what a keyboard is, this is not their responsibility

How to read multiple lines in string until specified character in C [closed]

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 6 years ago.
Improve this question
Need to read everything until say *** comes up:
Input:
Hey there
how are
you
***
Output:
Hey there
how are
you
Would have used scanf("%[^***]s) but can't read all lines at once.
Only having basic C knowledge
The way I would do this is read one line at a time (with a funcion such as fgets instead of scanf) and then see if the line that you last read is equal to ***. You can use use strcmp to do that but you can also do it by hand if you are not allowed to use strcmp for some reason.

Interpreting a shellcode [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
I am calling a shellcode using buffer overflow to spawn a root shell. Can somebody explain what this shellcode exactly does? I have tried different shellcodes to spawn a root shell, but this was the only one which worked for me.
\x31\xdb\x89\xd8\xb0\x17\xcd\x80\x31\xdb
\x89\xd8\xb0\x2e\xcd\x80\x31\xc0\x50\x68
\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89
\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd
\x80
On first glance, the code appears to do setuid(0), then setgid(0), then call sys_execve() on some values (which include ASCII codes for "/bin//sh").
Looks like this is pure "payload" code, since I don't see anything to ensure the code is executed on the first place (buffer overflow, stack smashing, etc.).
(Thanks to #Hans Lub for the disassembler link)

Resources