• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Simple C code won't compile Help!

ManyBeers

Platinum Member
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
 
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.
 
Good!

But the real question is, did it work? 😉

Lots of things compile that don't work. 😛
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)?
 
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.
 
Back
Top