Home > Back-end >  LNK1120 & LNK2019 in C
LNK1120 & LNK2019 in C

Time:03-26

So my program won't build just getting 1 unresolved externals and unresolved external symbol delay referenced in function main. It's not optimized at alla and wierdley coded but just ignore it

#include <stdio.h>
int main() {
    int nummer, nummer2, sant;
    printf("Skriv in ett nummer: ");
    scanf_s("%d", &nummer);
    while (1) {
    delay(100);

        if (nummer % 2 == 0)
            sant = 0;
        else
            sant = 1;

        if (nummer % 2 == 0) {
            nummer2 = nummer / 2;
            printf("nummer: %d", nummer2);
            nummer = nummer2;
        }
        else {
            nummer2 = nummer * 3   1;
            printf("nummer: %d", nummer2);
            nummer = nummer2;
        }
    }
}

CodePudding user response:

You don't say which compiler you are using. At a guess it is Microsoft 2019. The delay function is called Sleep (uppercase s) and it is in milliseconds. It lives in the Windows.h file.

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdio.h>
...

   /* Sleep 100ms */
   Sleep(100);

Not that it makes a lot of difference on the faster processors nowadays: WIN32_LEAN_AND_MEAN excludes many of the unnecessary header files that are pulled in by Windows.h

  •  Tags:  
  • c
  • Related