gjbex / dpd Goto Github PK
View Code? Open in Web Editor NEWRepository for the FutureLearn MOOC "Defensive programming and debugging"
License: GNU General Public License v3.0
Repository for the FutureLearn MOOC "Defensive programming and debugging"
License: GNU General Public License v3.0
The MOOC quiz 1.16, question 12, seems to suggest that the only issues with this code are that the main function should check whether there is an argument and whether that argument contains only letters (the latter being questionable, as one might want to check for palindromic numbers).
But the pal
function (called is_palindrome
in the MOOC) contains several errors that render it non-functional. An IMHO correct implementation is:
int pal(char a[]) {
if (strlen(a))
if (a[0] != a[strlen(a)-1])
return 0;
else {
a[strlen(a)-1] = 0;
return pal(&(a[1]));
}
else
return 1;
}
(I'm not submitting a PR as I'm wondering if the errors are supposed to be in there.)
Moreover, even if working as intended (?), the pal
function will overwrite the string passed to it, so that the printf
call in the main
function won't print the original string. Using pal(strdup(argv[1]))
instead of pal(argv[1])
can fix this, though strictly one should also check that the strdup
call succeeds.
If the errors are intended, maybe there should be an additional answer option: "Error handling is not required at this stage, as the program should first be made to work correctly."
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.