moving from gitlab
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
FILE *file = fopen("words.txt", "r");
|
||||
if (!file) {
|
||||
fprintf(stderr, "Error opening file");
|
||||
return -1;
|
||||
}
|
||||
char buffer[256];
|
||||
int lineCount = 0, wordCount = 0;
|
||||
|
||||
while (fgets(buffer, sizeof(buffer), file)) {
|
||||
lineCount++;
|
||||
if (buffer[0] == '\n')
|
||||
continue;
|
||||
|
||||
for (int i = 0; buffer[i] != '\0'; i++) {
|
||||
if (buffer[i] == ' ' || buffer[i] == '\n') {
|
||||
wordCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Number of Lines: %d\n", lineCount);
|
||||
printf("Number of Words: %d\n", wordCount);
|
||||
|
||||
fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
hey this is a file with words in it
|
||||
|
||||
it has newlines and spaces
|
||||
|
||||
lets a program to figure out the number of lines and words.
|
||||
Reference in New Issue
Block a user