I have problems running the following C written code in CodeBlocks:
#include <stdio.h>
#include <stdlib.h>
#define STRLEN 5
int readln(char s[], int maxlen) {
char ch;
int i;
int chars_remain;
i = 0;
chars_remain = 1;
while (chars_remain) {
ch = getchar();
if ((ch == '\n') || (ch == EOF)) {
chars_remain = 0;
} else if (i < maxlen - 1) {
s[i] = ch;
i++;
}
}
s[i] = '\0';
return i;
}
int main(int argc, char **argv) {
char firstname[STRLEN];
char lastname[STRLEN];
int len_firstname;
int len_lastname;
printf("Enter your first name:");
len_firstname = readln(firstname, STRLEN);
printf("Enter your last name:");
len_lastname = readln(lastname, STRLEN);
printf("Hello, %s, %s\n", firstname, lastname);
printf("Length of firstname = %d, lastname = %d", len_firstname, len_lastname);
}
This is the error message:
undefined reference to `WinMain@16' error: ld returned 1 exit status
So I am new to this, but I think it has something to do with my compiler. Any clues on how to fix it are greatly appreciated!