locked
Alphanumeric values- RRS feed

  • Question

  • hello;

    like to input a simple value like 2, we use scanf("&d", x); provided we have already entered #include<stdio> and int x

    what do we use if i want to enter an alphanumeric value like:   TP036

    Give maximum details please-


    • Edited by Azzzzhar Thursday, April 28, 2016 12:08 PM
    Thursday, April 28, 2016 12:07 PM

Answers

  • thank you so much, it works-

    • Proposed as answer by Hart Wang Friday, April 29, 2016 8:11 AM
    • Marked as answer by Hart Wang Wednesday, May 4, 2016 6:15 AM
    Thursday, April 28, 2016 12:59 PM

All replies

  • hello;

    like to input a simple value like 2, we use scanf("&d", x); provided we have already entered #include<stdio> and int x

    what do we use if i want to enter an alphanumeric value like:   TP036

    Give maximum details please-

    I think you mean a string value. Try this program:

    #include <stdio.h>
    
    int main()
    {
        char buf[256];
        scanf("%s", buf);
        printf("%s\n", buf);
        return 0;
    }
    

    But you need to be sure that 'buf' is big enough, or you wil get a buffer overrun. Better to use scanf_s or std::cin.


    David Wilkinson | Visual C++ MVP

    • Edited by davewilk Thursday, April 28, 2016 12:33 PM
    • Proposed as answer by David Roller Thursday, April 28, 2016 9:29 PM
    Thursday, April 28, 2016 12:32 PM
  • thank you so much, it works-

    • Proposed as answer by Hart Wang Friday, April 29, 2016 8:11 AM
    • Marked as answer by Hart Wang Wednesday, May 4, 2016 6:15 AM
    Thursday, April 28, 2016 12:59 PM
  • hello;

    like to input a simple value like 2, we use scanf("&d", x); provided we have already entered #include<stdio> and int x

    what do we use if i want to enter an alphanumeric value like:   TP036

    Give maximum details please-


    I hope you are using %d and &x.
    Thursday, April 28, 2016 7:03 PM
  • thank you so much, it works-

    Hi,

    Thank you for posting here. Since the problem has been resolved please mark the thread to help other people.

    Best Regards,

    Hart


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Friday, April 29, 2016 8:11 AM