Coder Social home page Coder Social logo

gjbex / dpd Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 94.0 158 KB

Repository for the FutureLearn MOOC "Defensive programming and debugging"

License: GNU General Public License v3.0

C 55.04% Fortran 39.33% Makefile 2.10% Shell 1.66% C++ 1.30% Python 0.58%

dpd's People

Contributors

gjbex avatar ingridbr avatar pvag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dpd's Issues

Several errors in Week1/C/palindrome.c

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."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.