NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

gets() doesn't work

 
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users
View previous topic :: View next topic  
Author Message
Pakbert



Joined: 11 Oct 2017
Posts: 1

PostPosted: Wed Oct 11, 2017 6:02 pm    Post subject: gets() doesn't work Reply with quote

Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
   
    char ageString[10];
    int age;
    int bonus;
   
    printf("Enter you age : ");
    gets(ageString);
    //fgets(ageString, 10, stdin);
    age = atoi(ageString);
   
    if (age > 45) {
        bonus = 1000;
    } else {
        bonus = 500;
    }
    printf("Your age is %d, and your bonus is %d.", age, bonus);

    return (EXIT_SUCCESS);
}


using gets() doesn't work here, i even use fgets() and still not working. thanks for any help
Back to top
soldatov



Joined: 05 Nov 2009
Posts: 597

PostPosted: Wed Oct 11, 2017 7:24 pm    Post subject: Reply with quote

What does"gets() doesn't work" mean? I checked your code works nicely.
P.S. Only if you uses Windows and MinGW/MSYS I expect problems with input.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo