어제 내용 복습 중 알아낸 것

undefined reference to `get_string'

에러 시 해결 방법 :

$ clang prc.c -lcs50 -o prc

이렇게 컴파일링 해본다.

실행했던 코드 :

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

int main(void){
    string animal = get_string("What is your favorite animal?\n");
        printf("my favorite animal is, %s\n", animal);
}

What is your favorite animal?
monkey
my favorite animal is, monkey

간단한 c코드였지만 에러가 어제부터 나서 맥 문제인 줄 알았는데 스택오버플로어에 여러 해답이 있었다.

  1. 아마 파일 경로 문제였던 거 같다. 다른 폴더에 해놓고 같은 명령어 입력했는데 이번에는 대문자 변경되는 식 실습할 수 있었다.
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    string s = get_string("Before: ");
    printf("After:  ");
    for (int i = 0, n = strlen(s); i < n; i++)
    {
        printf("%c", toupper(s[i]));
    }
    printf("\n");
}

Before: apple
After:  APPLE
  1. 3과 마지막 코드는 이해 될 듯 말 듯 하다. 자기 자신을 인자로 받는 것 같은데.. 정확한 알고리즘까지는 모르겠다. 다른 언어를 공부하다보면 알게 될 것 같기도 하다.
profile
커피 내리고 향 맡는거 좋아해요. 이것 저것 공부합니다.

0개의 댓글