#something that parse a file?
65 messages · Page 1 of 1 (latest)
10/10 for no using namespace std
i think you could have less nested loops
ik
if (File) is not the best way to check if a file is opened correctly iirc
What is "1 month"?
Like, the answer we give you can vary from incredibly good to horseshit depending on it.
E.g. if by "1 month" you mean that you started 30 days ago and did 1 hour per week, and had no prior experience, then this is a 10/10.
If by "1 month" you mean that you now have 30 * 24 = 720 hours actively working with C++ and you were already familiar with programming and tons of other, similar languages, then this is a 1/10.
about 3 hours a day with no prior compuer science or programming knowloedge
should be if (File.good()) i'm pretty sure
this checks all flags
im looking for feedback about the code not if i learnt a lot or not in this month
The if should be if (File), since the difference is the EOF (and an empty file is opened correctly, just well, empty), the while should be while (File.good())
toupper / tolower should be std::toupper and std::tolower (and maybe static_cast<char> somewhere? not sure)
ah, yes
YOU ASKED whether it was good for 1 month.
I only wanted to clarify what you even meant by 1 month
ok still allows me to use it without the std namespace
idk why
toupper, tolower, toupper_l, tolower_l - convert uppercase or lowercase
#include <ctype.h>
int toupper(int c);
int tolower(int c);
int toupper_l(int c, locale_t locale);
int tolower_l(int c, locale_t locale);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
toupper_l(), tolower_l():
Since glibc 2.10:
_XOPEN_SOURCE >= 700
... (truncated)
i though it was native form c++
yep, C++ headers usually include C headers
oh so C stuff doesnt contain the std namespace?
Well, C doesn't have such a thing as namespaces
so if (File) is ok to check for validating if files been opened sucesfully and i could do while(!File.eof())?
to check just for endoffile flag since i already know file is opened
No, because there could be other error that happen while reading the file that are neither EOF, nor apparent when opening the file
This, to me, feels very stream-of-conciousness writing (i.e. adding cases one after another), which often happens in first revisions, you can try pulling out reused code, and it should likely become significantly more readable (or try rewriting it again using some of the things you learned from this revision
You just uploaded the files here and not to, like, github. -1 point
Everything is in main(). No helper functions or classes. -1 point
And you didn't even specify what the program is exactly supposed to do. And it isn't very clear from the code either. -1 point
also, instead of using nested loops i could have done bunch of OPERATION control variables eg bool IsSection
I don't like this style of error handling:
if(everything ok){
do_stuff
} else {
error!!!
}
This creates a lot of nested ifs
I prefer:
if(something wrong){
error!!!!
exit program
}
do_stuff..
basically while parsing through "[jhaduga]" i set IsSection bool to true
so all char parsed within [] are asigned to a string
i think thats way cleaner and prob how parsing is done
@surreal galleon
so i just only have a main loop to parse all file and just a lot of ifs to do the asigment control
no nested loops are required
What you prefer actually also has a name:
Guard clauses
I would do a significantly different approach instead of character-by-character, the file format lends itself more to:
if(File.good() && File.peek() == '[')
sectionName = readUntil(']');
else
data = readData();
yeah that also could work
^^
Also, "real parsing" is usually done with recursive descent parsers and other more high-level algorithms, which aren't really necessary here; Or they are done with Flex + Bison, which generate recursive descent and other parser families, though as with a self-implemented recursive descent parser, this is overkill in this application
what do you mean by recursive descent parseing?
It's a type of algorithm for parsing context-free-grammars: https://en.wikipedia.org/wiki/Recursive_descent_parser (A high-level overview from Wikipedia)
In computer science, a recursive descent parser is a kind of top-down parser built from a set of mutually recursive procedures (or a non-recursive equivalent) where each such procedure implements one of the nonterminals of the grammar. Thus the structure of the resulting program closely mirrors that of the grammar it recognizes.
A predictive par...
Though if you don't know automata theory it's a real rabbit hole, so the TL;DR is that it's overkill for this application
indeed
anyways ty for the feedback
i want to improve my algorithmic skills and basically "thinking", i know best way is just to code and keep coding
im all ears to advises
I would say don't worry about time complexity and parsing just yet, since these are higher-level concepts that don't make sense without a solid foundation in CS theory, the best advice (IMO) is to try and write reusable code in functions, and try to see patterns in what you're writing (and if you look in projects what they're doing), and then look into books/classes on Data Structures+Algorithms and other CS theory concepts
i coded it like that becouse i was never introduced to functions
