Sublime Forum

Error message in first program with main() - can anyone help

#1

Hi - I’m trying to learn the first steps in programming. I have entered the following first program

#include <stdio.h>
main()
{
printf(“text”)
etc etc

but keep getting the same error for the second line.

warning: type specifier missing, defaults to ‘int’ [-Wimplicit-int]

I have tried variants and a few suggestions from other sites but nothing works. I’m sure I’m making a very basic error but can’t figure out what. Can anyone help?

0 Likes

#2

I believe you just copy and paste the warning message into the Google Search input text box and it will tell the reason and solution…

0 Likes

#3

Your function doesn’t specify what type of value that it returns. Classically in C any function that doesn’t define a return value is assumed to return an int, but it’s bad style and can mask bugs to rely on inferred returns.

Try defining main as:

int main(int argc, const char **argv)
0 Likes

#4

Thanks - tried this already though - all the examples didn’t seem to work.

0 Likes

#5

Thanks for this - I pasted this in, but keep getting the same error message…

0 Likes

#6

Would you mind sharing the whole file?

0 Likes

#7

It’s OK - I finally figured it out. I used the int main(void) - which didn’t work until I re-saved it in a new file, then used build with then build and run - finally got it to work. Bit of a fan but got there.

But thanks for the offer of help!

0 Likes