0

I am in week 1 on CS50 2017, and in the lecture he presents a code written as follows:

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

int main(void);
{
    int n = 0;
    while (true)
    {
        printf("n is %i\n", n);
        n++;
    }
}

This code is verbatim what he has typed, and yet it won't compile. I receive this error back:

overflow.c:5:1: error: expected identifier or '('
{
^

Please help! I have searched all over for a solution and can not seem to find one... I understand this is a simple and useless program, but I am trying to learn by writing all of the programs along with him and it is frustrating that when he compiles, the program works just fine, when I do it, I am presented with an error. Thanks! -Austin

0
0

I just finished week 2 but there should not be the semicolon at the end of your 3rd line:

 int main(void)
 {

 }
0

Remember when you declare a function prototype, usually at the very top before main, you use a ";" but when you actually right the function you do not.

int main(void) 
{
    ....
    ....
}

if i go for a prototype i do.

#include <stdio.h>
int getline(char line[], int maxline);

int main(void) 
{
    ....
    ....
}

getline is a prototype which i will use somewhere below to get a line of text. I will write it out below as well.

You must log in to answer this question.

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