I as the title says I am trying to create a function that will return 3 values when reading a document for an assignment. I wanted to make it work in a function, so I can just call that function and it will output the 3 values, but at the moment the Developer prompt is just running endlessly and not printing anything. Below is a snippet of my code if anybody could help.
#include <stdio.h>
#include <string.h>
#define LINE 1000
void countLines(int *emptyLines, int *totalLines, int *totalComments)
{
char line[LINE];
*emptyLines = 0;
*totalLines = 0;
*totalComments = 0;
FILE *input = fopen("student.java", "r");
while (fgets(line, LINE, input)) {
int i;
int len = strlen(line);
char *delimiters = " . , \n \t";
char *token = strtok(line, delimiters);
for (i = 0; i < len; i++) {
if (line[i] != '\n' && line[i] != '\t' && line[i] != ' ') {
emptyLines++;
break;
}
} // counts all the lines that aren't empty
while (token != NULL) {
if (strcmp(token, "/**") == 0) {
totalComments++;
}
} // counts the total amount of comments
totalLines++; // counts the total amount of lines
}
fclose(input);
}
int main(int argc, char **argv) {
FILE *input = fopen("student.java", "r");
int emptyLines, totalLines, totalComments;
countLines(&emptyLines, &totalLines, &totalComments);
printf("There are %d total lines, %d lines of code and %d comments in the file\n",
totalLines, emptyLines, totalComments);
return 0;
}