Simple C code won't compile Help!

ManyBeers

Platinum Member
Aug 30, 2004
2,519
1
81
Code:
#include <stdio.h>
#include <string.h>

int main()

{
    char buffer[256];
     
     printf("Enter your name and press <Enter>:\n");
     gets(buffer);
     
     printf("\nYour name has %d characters and spaces!", strlen(buffer));
                       
    return 0;
}
I am using the book Teach Yourself C in 21 days and this sample doesn't compile
anybody no why it doesn't. I use Notepad++ and MinGW on Vista and the other samples so far compiled.
The error I get....28:9: error: .. expected unqualified id before numeric constant
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
Compiles and runs fine with MSVC and gcc 4.8.1. Post the full text of the error message.
 

Gryz

Golden Member
Aug 28, 2010
1,551
204
106
Don't use gets(3). Evar.

That routine should be removed from the library and from examples in books. It's the root of all buffer-overflow bugs.
 

ManyBeers

Platinum Member
Aug 30, 2004
2,519
1
81
Good!

But the real question is, did it work? ;)

Lots of things compile that don't work. :p
Yes it compiled and ran in Xubuntu 12.04 but not in Vista. I normally use Xubuntu when learning C but I will also use Windows. Apparently there is something distasteful to MinGW in this bit of code. Hey where is the best place for answers
if I need them in the future(which I most definitely will)?
 
Feb 25, 2011
17,000
1,628
126
Yes it compiled and ran in Xubuntu 12.04 but not in Vista. I normally use Xubuntu when learning C but I will also use Windows. Apparently there is something distasteful to MinGW in this bit of code. Hey where is the best place for answers
if I need them in the future(which I most definitely will)?
Well, you're always welcome here, but when I'm trying to hack something together, my desperate googling usually leads me to StackOverflow.