Thread: Hello experts! Me having some trouble with integer variable (17 printed as -28786)

  1. #1
    Registered User
    Join Date
    Aug 2017
    Posts
    28

    Hello experts! Me having some trouble with integer variable (17 printed as -28786)

    Here is my code :

    Code:
    //Program in C
    /* Revising methods strch()
    * and strcmp() with stricmp(). */
    
    
    
    
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    
    main() {
    clrscr();
    
    
    char ip_string[30];
    char *ptr;
    //Prompting user randomly, taking greet string
    printf("Hey Hello! Greet me somehow. ");
    fgets(ip_string, 20, stdin);
    
    
    //Showing their entered string
    printf("This is your input >%s<\n", ip_string);
    
    
    /* Now trimming their input for
    * any '\n' if exist
    */
    if ((ptr = strchr(ip_string, '\n'))) {
        *ptr = NULL;
    }
    //Now putting formatted output
    
    
    printf("New output is >%s<\n", ip_string);
    
    
    //Playing with user
    char f_name[25];
    printf("User enter your full name please: ");
    fgets(f_name, 25, stdin);
    int age;
    
    
    printf("What's your age by the way? ");
    scanf("%d", age);
    
    
    printf("Now I know you better. You are %s ,and your age is %d", f_name, age);
    getch();
    
    
    return(0);
    }
    And output screen:

    Hello experts! Me having some trouble with integer variable (17 printed as -28786)-output-jpg

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,732
    scanf at line #48 needs a pointer to "age", not the value of "age".

    Turn on your compiler's warnings btw, there are other things you should fix too.

    Also, just in case, please stop using TurboC. conio and family are windows-only and ancient.
    Last edited by GReaper; 08-28-2017 at 07:51 AM.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Aug 2017
    Posts
    28
    Thanks man. I am so silly that i didn't noticed that.

  4. #4
    Registered User
    Join Date
    Aug 2017
    Posts
    28
    And please help me out choosing a better IDE.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,732
    Quote Originally Posted by kdushyant297 View Post
    And please help me out choosing a better IDE.
    I recommend CodeBlocks to everyone but there are others. Eclipse, Codelite, Orwell DevC++, NetBeans, take your pick.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    101
    [...]

    Quote Originally Posted by GReaper View Post

    Also, just in case, please stop using TurboC. conio and family are windows-only and ancient.
    I use Code::Blocks IDE in Ubuntu with Clang compiler. For MS Windows OP may try the Code::Blocks and Mingw bundle from this download link.

    Another option is Geany IDE.

    OP may use these flags or even more for Mingw:
    -Wall -pedantic -ansi

    Clang compiler may provide c11 support though.

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    On windows I would recommend VS2017 Community edition
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  8. #8
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    If you want to learn GUI programming C++ Builder is a good option.
    C++Builder Starter - Embarcadero Website

  9. #9
    Registered User
    Join Date
    Aug 2017
    Posts
    28
    Thanks everyone for your assists. I installed codeblocks, and looks pretty well to me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-04-2015, 10:06 AM
  2. Replies: 7
    Last Post: 09-19-2011, 01:37 PM
  3. Replies: 7
    Last Post: 09-04-2011, 09:29 PM
  4. Replies: 8
    Last Post: 03-26-2007, 05:48 PM
  5. Had somee trouble with the reject integer cod......
    By SkyRaign in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 10:39 PM

Tags for this Thread