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

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.

Related

How to get input from user via command line while bison/flex reads file? [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 4 days ago.
Improve this question
I'm new to flex and bison and i couldn't figure it out. I want to read a file. This is okey for now. But while bison/flex parse and read file, I want to make it wait for new input and get it from command line. Is there a keyword or way to do it?
I tried abort yyparse() with yyerror() and get input by scanf(). But it didn't work. It doesn't wait for input and goes on.
I did a project school named mini_shell and what we asked to do was to code something like bash.
the main thing was to wait for user input and execute the command he entered, you can do that by a function named.
char *readline(const char *prompt); (you can read the man page to understand more https://man7.org/linux/man-pages/man3/readline.3.html) but I think you need to install it first before you can use it, you can find a lot of tutorials explaining how to do that based on your OS.

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

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.

Weird issue 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 6 years ago.
Improve this question
thanks for your help.
I'm trying to similate a simplified version of ARM, and I have a very weird error in c http://pastebin.com/3XRdngty .
I don't understant why in the function executer_code(),
the for doesn't work ...
I mean it should be looping untill the variable "i" is equal to the variable nombre_instruction, but it turns out that the variable "nombre_instruction" is the right value the first time it goes in the for, but the second time it doesn't go in the for because its value changed to 0, I search on the internet if someone has the same kind of error, and i didn't find anything.I reread my code but still I cannot figure out why it does this, 3 hours has passed already.
And thank you again for you help :)
This is taken from your code:
char *compar;
if(i==0){
sprintf(&compar,"%c%c%c%c",code[0],code[1],code[2],code[3]);
}
The problem here is that you declare compar as a pointer to char, but it is uninitialized. So, it has an undefined value. When you fill it with sprintf, you just write somewhere in the memory, and apparently, you write over the variable nombre_instruction.
Solution:
char compar[200];

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 .

Resources