In function ‘main’: cntwlc.c:20:2: error: parameter ‘num_lines’ is initialized int num_lines = 0, num_words = 0, num_chars = 0, num_alpha = 0, num_digits = 0, num_special = 0; ^ cntwlc.c:20:2: error: parameter ‘num_words’ is initialized cntwlc.c:20:2: error: parameter ‘num_chars’ is initialized cntwlc.c:20:2: error: parameter ‘num_alpha’ is initialized cntwlc.c:20:2: error: parameter ‘num_digits’ is initialized cntwlc.c:20:2: error: parameter ‘num_special’ is initialized cntwlc.c:21:2: error: expected declaration specifiers before ‘printf’ printf("Welcome to cntwlc the CIS158 version of the word count.\n\n"); ^ cntwlc.c:22:2: error: expected declaration specifiers before ‘printf’ printf("This program will produce statistics about the text entered from standard in.\n\n"); ^ cntwlc.c:23:2: error: expected declaration specifiers before ‘printf’ printf("Please enter your text now. When finished enter a control d to end,\n\n"); ^ cntwlc.c:24:2: error: expected declaration specifiers before ‘printf’ printf("--\nText Statistics:\n\n"); ^ cntwlc.c:25:2: error: expected declaration specifiers before ‘While’ While (fgets(line, MAX_LINE, stdin)) ^ cntwlc.c:52:2: error: expected declaration specifiers before ‘printf’ printf("Lines\n%d\n\n", num_lines-1); ^ cntwlc.c:53:2: error: expected declaration specifiers before ‘printf’ printf("Words\n%d\n\n", num_words); ^ cntwlc.c:54:2: error: expected declaration specifiers before ‘printf’ printf("Characters\n%d\n", num_chars-1); ^ cntwlc.c:55:2: error: expected declaration specifiers before ‘printf’ printf("Alphabetic\n%d\n", num_alpha); ^ cntwlc.c:56:2: error: expected declaration specifiers before ‘printf’ printf("Digits\n%d\n", num_digits); ^ cntwlc.c:57:2: error: expected declaration specifiers before ‘printf’ printf("Special\n%d\n\n", num_special); ^ cntwlc.c:58:2: error: expected declaration specifiers before ‘printf’ printf("Thank you for using cntwlc. Bye!\n"); ^ cntwlc.c:59:2: error: expected declaration specifiers before ‘return’ return 0; ^ cntwlc.c:60:2: error: expected declaration specifiers before ‘}’ token } ^ cntwlc.c:17:5: error: old-style parameter declarations in prototyped function definition int main(void) ^ cntwlc.c:60:2: error: expected ‘{’ at end of input } ^ CODE THAT NEEDS CORRECTION: #include #include #define MAX_LINE 1000 int main(void) char line[MAX_LINE]; int num_lines = 0, num_words = 0, num_chars = 0, num_alpha = 0, num_digits = 0, num_special = 0; printf("Welcome to cntwlc the CIS158 version of the word count.\n\n"); printf("This program will produce statistics about the text entered from standard in.\n\n"); printf("Please enter your text now. When finished enter a control d to end,\n\n"); printf("--\nText Statistics:\n\n"); While (fgets(line, MAX_LINE, stdin)) { num_lines++; int in_word = 0; for (int i = 0; line[i] != '\0'; i++) { if (isspace(line[i])) { in_word = 0; } else{ if (!in_word) { num_words++; in_word = 1; } if (isalpha(line[i])) { num_aplha++; } else if (isdigit(line[i])){ num_digits++; } else if (!isspace(line[i])) { num_special++; } } num_chars++; } } printf("Lines\n%d\n\n", num_lines-1); printf("Words\n%d\n\n", num_words); printf("Characters\n%d\n", num_chars-1); printf("Alphabetic\n%d\n", num_alpha); printf("Digits\n%d\n", num_digits); printf("Special\n%d\n\n", num_special); printf("Thank you for using cntwlc. Bye!\n"); return 0; } Example of Output [s158a00@cisweb ex0]$ cntwlc
Can someone help me fix and correct this C program .It fails to compile and run .Ive tried everything .It is supposed to come out exactly like the example output.I keep geting these error codes during compilation.
ERRORS GIVEN DURING COMPILATION:
In function ‘main’:
cntwlc.c:20:2: error: parameter ‘num_lines’ is initialized
int num_lines = 0, num_words = 0, num_chars = 0, num_alpha = 0, num_digits = 0, num_special = 0;
^
cntwlc.c:20:2: error: parameter ‘num_words’ is initialized
cntwlc.c:20:2: error: parameter ‘num_chars’ is initialized
cntwlc.c:20:2: error: parameter ‘num_alpha’ is initialized
cntwlc.c:20:2: error: parameter ‘num_digits’ is initialized
cntwlc.c:20:2: error: parameter ‘num_special’ is initialized
cntwlc.c:21:2: error: expected declaration specifiers before ‘printf’
printf("Welcome to cntwlc the CIS158 version of the word count.\n\n");
^
cntwlc.c:22:2: error: expected declaration specifiers before ‘printf’
printf("This program will produce statistics about the text entered from standard in.\n\n");
^
cntwlc.c:23:2: error: expected declaration specifiers before ‘printf’
printf("Please enter your text now. When finished enter a control d to end,\n\n");
^
cntwlc.c:24:2: error: expected declaration specifiers before ‘printf’
printf("--\nText Statistics:\n\n");
^
cntwlc.c:25:2: error: expected declaration specifiers before ‘While’
While (fgets(line, MAX_LINE, stdin))
^
cntwlc.c:52:2: error: expected declaration specifiers before ‘printf’
printf("Lines\n%d\n\n", num_lines-1);
^
cntwlc.c:53:2: error: expected declaration specifiers before ‘printf’
printf("Words\n%d\n\n", num_words);
^
cntwlc.c:54:2: error: expected declaration specifiers before ‘printf’
printf("Characters\n%d\n", num_chars-1);
^
cntwlc.c:55:2: error: expected declaration specifiers before ‘printf’
printf("Alphabetic\n%d\n", num_alpha);
^
cntwlc.c:56:2: error: expected declaration specifiers before ‘printf’
printf("Digits\n%d\n", num_digits);
^
cntwlc.c:57:2: error: expected declaration specifiers before ‘printf’
printf("Special\n%d\n\n", num_special);
^
cntwlc.c:58:2: error: expected declaration specifiers before ‘printf’
printf("Thank you for using cntwlc. Bye!\n");
^
cntwlc.c:59:2: error: expected declaration specifiers before ‘return’
return 0;
^
cntwlc.c:60:2: error: expected declaration specifiers before ‘}’ token
}
^
cntwlc.c:17:5: error: old-style parameter declarations in prototyped function definition
int main(void)
^
cntwlc.c:60:2: error: expected ‘{’ at end of input
}
^
CODE THAT NEEDS CORRECTION:
#include <stdio.h>
#include <ctype.h>
#define MAX_LINE 1000
int main(void)
char line[MAX_LINE];
int num_lines = 0, num_words = 0, num_chars = 0, num_alpha = 0, num_digits = 0, num_special = 0; printf("Welcome to cntwlc the CIS158 version of the word count.\n\n");
printf("This program will produce statistics about the text entered from standard in.\n\n");
printf("Please enter your text now. When finished enter a control d to end,\n\n");
printf("--\nText Statistics:\n\n");
While (fgets(line, MAX_LINE, stdin))
{
num_lines++;
int in_word = 0;
for (int i = 0; line[i] != '\0'; i++)
{
if (isspace(line[i]))
{
in_word = 0;
} else{
if (!in_word)
{
num_words++;
in_word = 1;
}
if (isalpha(line[i]))
{
num_aplha++;
} else if (isdigit(line[i])){
num_digits++;
} else if (!isspace(line[i])) {
num_special++;
}
}
num_chars++;
}
}
printf("Lines\n%d\n\n", num_lines-1);
printf("Words\n%d\n\n", num_words);
printf("Characters\n%d\n", num_chars-1);
printf("Alphabetic\n%d\n", num_alpha);
printf("Digits\n%d\n", num_digits);
printf("Special\n%d\n\n", num_special);
printf("Thank you for using cntwlc. Bye!\n");
return 0;
}
Example of Output
[s158a00@cisweb ex0]$ cntwlc <testFile
Welcome to cntwlc the CIS158 version of word count.
This program will produce statistics about the text entered from standard
in.
Please enter your text now. When finished enter a control D to end.
--- Text Statistics: ---
Lines 5
Words 37
Characters 188
Alphabetic 139
Digits 3
Special 9
Thank you for using cntwlc. Bye!
Step by step
Solved in 3 steps with 1 images