made work: count the number of words in a file

This commit is contained in:
Odweta
2023-12-29 17:20:53 +01:00
parent e15a60c43b
commit 5374cf7191
3 changed files with 65 additions and 48 deletions
+1 -1
View File
@@ -22,10 +22,10 @@ To create a project that uses this library easier, use the `vendetta` utility (`
6. Deleting a file 6. Deleting a file
7. Checking if a file exists 7. Checking if a file exists
8. Add line numbers at the beggining of each line in a file (with correct indentation) 8. Add line numbers at the beggining of each line in a file (with correct indentation)
9. Number of words in a file
#### TODO: #### TODO:
1. Number of words in a file
+ You tell me + You tell me
+21 -5
View File
@@ -27,15 +27,28 @@ int main() {
char *string = fileToString(f); char *string = fileToString(f);
printf("\"\"\"\n%s\"\"\"\n", string); printf("\"\"\"\n%s\"\"\"\n", string);
printf("writing is quite simple, just call the 'fileWrite(file_t*, char*)' or 'fileWriteln(file_t*, char*)' function, where the second argument is the string you want to write into a file\nthe 'fileWriteln()' function writes the specified string AND a '\\n' after it, whereas the 'fileWrite()' function does not append the '\\n'\n"); printf("writing is quite simple, just call the 'fileWrite(file_t*, char*)' "
"or 'fileWriteln(file_t*, char*)' function, where the second argument "
"is the string you want to write into a file\nthe 'fileWriteln()' "
"function writes the specified string AND a '\\n' after it, whereas "
"the 'fileWrite()' function does not append the '\\n'\n");
fileWrite(f, "'this will not end with a \"\\n\"' "); fileWrite(f, "'this will not end with a \"\\n\"' ");
fileWriteln(f, "this line was appended"); fileWriteln(f, "this line was appended");
filePrint(f); filePrint(f);
printf("if you are finished working with the file BEFORE the immediate end of the program, run 'fileCleanup(file_t*)', otherwise it is not strictly necessary\nit will, though, append a '\\n' at the end of the file if you have not done so, making writing into files more consistent, so for this reason, I recommend you use it with every file_t*\n"); printf(
"if you are finished working with the file BEFORE the immediate end of "
"the program, run 'fileCleanup(file_t*)', otherwise it is not strictly "
"necessary\nit will, though, append a '\\n' at the end of the file if "
"you have not done so, making writing into files more consistent, so for "
"this reason, I recommend you use it with every file_t*\n");
fileCleanup(f); fileCleanup(f);
printf("copying and moving\nafter this block of code, the contents of test.txt will have been copied into copy_of_test.txt and moved to moved_copy_of_test.txt, which means that copy_of_test.txt is deleted and the contents of test.txt are only in test.txt and moved_copy_of_test.txt\n"); printf("copying and moving\nafter this block of code, the contents of "
"test.txt will have been copied into copy_of_test.txt and moved to "
"moved_copy_of_test.txt, which means that copy_of_test.txt is deleted "
"and the contents of test.txt are only in test.txt and "
"moved_copy_of_test.txt\n");
file_t *src = fileInit("test.txt"); file_t *src = fileInit("test.txt");
@@ -55,11 +68,14 @@ int main() {
filePrint(move_dst); filePrint(move_dst);
fileCleanup(src); fileCleanup(src);
printf("DO NOT cleanup a deleted file! (dst, in this case) it is already done for you by the 'fileMove(file_t*, char*)' function\n"); printf("DO NOT cleanup a deleted file! (dst, in this case) it is already "
"done for you by the 'fileMove(file_t*, char*)' function\n");
// fileCleanup(dst); // fileCleanup(dst);
fileCleanup(move_dst); fileCleanup(move_dst);
printf("when copying and moving files, the first argument is a file_t* (source file) and the second argument is a char* (the path of the destination file), not a file_t*!\n"); printf("when copying and moving files, the first argument is a file_t* "
"(source file) and the second argument is a char* (the path of the "
"destination file), not a file_t*!\n");
printf("prepending line numbers at the beggining of each line in a file\n"); printf("prepending line numbers at the beggining of each line in a file\n");
+1
View File
@@ -6,3 +6,4 @@ this was an empty line
!#%!@# <- symbols! !#%!@# <- symbols!
about 1100 lines of implementation code, not including .h files and demos and Makefiles and stuff like that about 1100 lines of implementation code, not including .h files and demos and Makefiles and stuff like that
'this will not end with a "\n"' this line was appended 'this will not end with a "\n"' this line was appended
'this will not end with a "\n"' this line was appended