Search code examples
ccs50

Can I use methods that not covered in related week in CS50?


Can I use methods that not covered in related week in CS50?

For example, Arrays didn't cover in Week 1, can I use arrays to submit "credit" problem.

#include <cs50.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    string cardNumber;
    int cardLength;

    do
    {
        cardNumber = get_string("Number: ");
        cardLength = strlen(cardNumber);
    } while(cardLength < 13 || cardLength > 16);

    for (int i = cardLength - 2; i > 0; i-= 2)
    {
        printf("%c \n", cardNumber[i]);

    }

}

Solution

  • Short answer: Yes.

    You can use any valid C, even if it has not been covered yet. If I remember correctly, the compiler uses std=c99 as a flag.

    Aside, if your rather ‘code properly’ (without training wheels) you don’t have to use the cs50 lib at all. David will take it away in a couple weeks anyways.