My code isn't compiling. I'm getting "undefined reference to 'get_string'" I think there is an issue with the way i have contextualized the first part of my code, i.e., above the "for" loop. I'm not sure how to proceed.

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

int main(int argc, string argv[])
    while (argc == 2)

    argv[1] = "3";
    int k = atoi(argv[1]);
    char c;

    string p = get_string("Plaintext: ");

    for (int i = 0, n = strlen(p); i < n; i++)
        // Checks for letters and uppercase
        if (isalpha(p[i]) && isupper(p[i]))
            // If uppercase, print as uppercase
            printf( "%c", (p[i]));
            // if not uppercase
        else if (isalpha(p[i]) && islower(p[i]))
            // print lowercase
            printf("%c", (p[i]));
    // If charecter is not a letter
            // Print non-letter character
            printf("%c,", p[i]);
        // Moves plaintext characters to ciphertext
        c = (p[i] + k) % 26;

        printf("ciphertext: %c", c);

1 Answer 1


get_string is found in the cs50 library, but it hasn't always been there. Maybe you have an old version of the library. If the compiler doesn't complain about missing cs50.h, and GetString instead of get_string works, that's the problem. If you are on cs50.io or similar, try update50. If you are using your own IDE, download the current version of the library from https://github.com/cs50/libcs50/

BTW, while (argc == 2) starts a loop. Its only content is statement argv[1] = "3";. I don't think that one is valid, and if it were, you were stuck in an infinite loop, as argc is not going to change. Maybe you meant if instead, also while and if usually become more readable if you wrap their body into curly braces {} even if it's just one statement.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .