what is wrong with my code it is not running
<code>#include <stdio.h>
#define IN 1
#define OUT 0
int main() {
int c, nl = 0, nw = 0, nc = 0, state = OUT;
printf("Enter your sentence (press Ctrl+D to stop the input):n");
while ((c = getchar())!= EOF) {
nc++;
if (c == 'n') {
nl++;
state = OUT;
}
else if (c == ' '|| c == 't') {
state = OUT;
}
else if (state == OUT) {
state = IN;
nw++;
}
}
printf("The number of words was found to be: %dn", nw);
printf("The number of characters was found to be: %dn", nc);
printf("The number of lines was found to be: %dn", nl);
return 0;
}
</code>
<code>#include <stdio.h>
#define IN 1
#define OUT 0
int main() {
int c, nl = 0, nw = 0, nc = 0, state = OUT;
printf("Enter your sentence (press Ctrl+D to stop the input):n");
while ((c = getchar())!= EOF) {
nc++;
if (c == 'n') {
nl++;
state = OUT;
}
else if (c == ' '|| c == 't') {
state = OUT;
}
else if (state == OUT) {
state = IN;
nw++;
}
}
printf("The number of words was found to be: %dn", nw);
printf("The number of characters was found to be: %dn", nc);
printf("The number of lines was found to be: %dn", nl);
return 0;
}
</code>
#include <stdio.h>
#define IN 1
#define OUT 0
int main() {
int c, nl = 0, nw = 0, nc = 0, state = OUT;
printf("Enter your sentence (press Ctrl+D to stop the input):n");
while ((c = getchar())!= EOF) {
nc++;
if (c == 'n') {
nl++;
state = OUT;
}
else if (c == ' '|| c == 't') {
state = OUT;
}
else if (state == OUT) {
state = IN;
nw++;
}
}
printf("The number of words was found to be: %dn", nw);
printf("The number of characters was found to be: %dn", nc);
printf("The number of lines was found to be: %dn", nl);
return 0;
}
I have tried changing the variable, running it on a different machine but still it is taking the input continuously and not giving me the results
New contributor
Suryansu Sanjeebani mohanty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.