Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CAN YOU PLEASE CODE THE ASSIGNMENT BELOW IN C ? THANKS A LOT IN ADVANCE. Best Pr

ID: 3882202 • Letter: C

Question

CAN YOU PLEASE CODE THE ASSIGNMENT BELOW IN C ? THANKS A LOT IN ADVANCE.

Best Practices for Code Style Your submissions must observe the following guidelines. Submissions which do not meet the guide- lines will have marks deducted, even if they function correctly (although some of the guidelines such as those relating to uninitialized memory, might also affect the ability of the program to work correctly on a reliable basis, which could result in a deduction for both style and function) » Submitted files must be syntactically correct and named according to the assignment speci- . Every source file must contain a comment (at or near the top of the file) with your name » The goto statement is not permitted in any assignment submissions. Instead, your code fication. student number, the date the code was written and a brief description of the program. should use structured control flow elements, like if, for and while . Global variables (data variables created outside of the scope of a function) are not permitted, except when explicitly allowed by the assignment. For this assignment, no global variables are permitted, except for const variables if needed. Every function with a non-void return type must return a value . Uninitialized variables may not be used before being assigned a value

Explanation / Answer

Please find my code to count words.

Please let me know in case of any issue.

#include <stdio.h>

#define OUT 0
#define IN 1

// returns number of words in file
unsigned countWords(char *file)
{
int state = OUT;
unsigned wc = 0; // word count

FILE * filp;
char c, lastChar;
filp = fopen(file, "r");
if(filp == NULL)
printf("file not found ");

while((c = fgetc(filp)) != EOF) {
// If next character is a separator, set the
// state as OUT
if (c == ' ' || c == ' ' || c == ' ')
state = OUT;

// If next character is not a word separator and
// state is OUT, then set the state as IN and
// increment word count
else if (state == OUT)
{
state = IN;
++wc;
}
}

fclose(filp);

return wc;
}

// Driver program to tes above functions
int main(void)
{
char file[20];
printf("Enter input file name: ");
scanf("%s", file);

printf("Number of words: %u ", countWords(file));
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote