201220014 / whalemarket Goto Github PK
View Code? Open in Web Editor NEWA C-Beginner Project for Winter Code Activity
License: Apache License 2.0
A C-Beginner Project for Winter Code Activity
License: Apache License 2.0
在您的功能设计里,买家并没有给自己充值的功能,导致新注册用户的购买操作总是失败。
首先,谢谢熊提供的tutorial,您真是电子佛祖 :)。
然后有几个问题,可能有些找茬吧,但也确实是我在完成项目过程中的疑惑:
在src/menu/menu.c的menu()函数的实现里,你用到了atoi()函数把用户输入的字符串转换成整数,但atoi()函数不能检查用户输入的字符串是否为整数。e.g.,如果我输入1,跳出while循环;如果我输入1st或者1aaa这样的字符串,依然能跳出while循环。
不只是这里会出现这种非法输入的问题,像涉及到用户余额、商品价格这种浮点数格式的数据,像上面那样不合法的输入也会被视为合法数据。
另外为啥用scanf()而不是fgets()接收用户的输入,它不能接收空格,这样我输入用户地址、商品描述这些信息时,输入里有个空格就报错输入非法。
这里主要说的是src/interface/userInterface.c中定义的curUser全局变量(还有一个curGood ,同理),它在头文件include/interface/interface.h中被声明,那所有包含了这个头文件的文件都可以对这个全局变量进行修改,不管是否应该这么做,比如在src/main.c就可以这样。
我看过一些博客都不推荐这么做,大致理由如上所述。如果不用全局变量记录当前用户的话,应该就只能用函数来传递参数了,但这么做,可能就无法使用HANDLE型的函数指针数组(不同函数的参数应该很难做到统一),代码就会变得比较冗余。那对于这种可能引起的安全性问题,你有什么好的解决方案吗?
还是以src/menu/menu.c这个文件为例,如果在采用你给出的项目框架的前提下,要包含menu.h这个头文件,可以采用以下两种写法:
#include "menu/menu.h"
#include "../../include/menu/menu.h"
第一种写法是你给出的,很简洁;第二种是我在做这个项目的时候写的,它等于就是说,当编译menu.c时,先返回上一级文件夹,再返回上一级文件夹,最后定位到include/menu/menu.h。看着确实很画蛇添足,但在我自己的项目里不按照第二种写法,根本通不过编译(找不到路径)。我问过GPT这个问题,可能是我没有描述好,它给出的回答也是错误的。请问你可以解释一下这个路径应该怎么写,或者提供一些关于如何写“include后面的文件路径”的官方资料?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.