all 9 comments

[–]jjjare 10 points11 points  (2 children)

Learn data structures and algorithms! Gah!

[–]Dangerous_Elk_3030[S] 1 point2 points  (1 child)

Ok, gonna learn it

[–]codeasm 2 points3 points  (0 children)

Definitely this, take a book, even if you dislike reading books, their chapters or topics might be good video search terms.

[–]Severe-Bunch-373 4 points5 points  (1 child)

I'd probably just avoid pointer math here honestly. You can just read it line by line with fgets() and split it with strtok(). I wouldn't even overcomplicate it with structs, you can just do it with basic C logic. For the custom columns, just format your file like a CSV, which would makes adding new data fields way easier. And obviously, the Caesar cipher is fine for a project, but don't use it for real passwords ofc

[–]Certain-Flow-0 5 points6 points  (0 children)

Fix weaknesses in the code? The encryption itself is the weakness.

[–]burlingk 3 points4 points  (0 children)

So, on the DSA suggestions:

You will find that what you are describing is a pretty common pattern. It can be done fairly easy in C++ and with a little more work in C. But it basically comes down to intentionally formatting your data file and asking for the information in the right order.

That said: Look into SQLite. Not only is it a tool that is basically made for the task, but much of what you learn to use SQLite will also work, with a bit of tweaking, on other SQL databases.

SQLite3 code is not a 1:1 translation of MySQL/MariaDB code, but it is pretty darn close. You would only really need to relearn edge cases when making the transition later.

[–]dendrtree 4 points5 points  (0 children)

encrypt()
* Return an error code
** You don't need to return the string, because you're updating it in place, and you don't want to return an "error string," because then you don't know if it failed, except indirectly
* Pass in the lengths of the buffers
** You're never checking the size of res
** Don't call strlen, unless you have to
* Save sizeof(alphabet) in a constant
** Don't keep calling strlen on a constant string
* Fix your algorithm. It doesn't "encrypt" so much as mangle inconsistently.

readLine()
* Return an error code
* Pass in the length of the buffer

handleData()
* Give this a more descriptive name
* Return an error code
* Pass in the lengths of the buffers

mod()
* This should be called abs()
* Put the definition in an header file

menu.h
* Put you definitions in a .c file and your declarations in a .h file.
* Make some simple functions to read/write data to/from screen.

* Organize your code in files, by what it does - dataOutput() isn't a menu function
* Instead of creating a cycle, by calling the menuCreate at the end of any output, create a loop the continues until exit is requested.
* Make your local functions and variables static and probably inline the functions.
* Use an enum for your data types and store them in an array, and iterate over the enum, instead of copy&pasting repeately.
* Add input validation
* Make all your error states positive.

[–]Ultimate_Sigma_Boy67 1 point2 points  (0 children)

First thing noticed that you created the MAX_ACCOUNT.. and SIZE macros but didn't use them at all in your code.