example output:
Meter number is: 124123ABC231
"what should i use to define something like that....
TurboC newbie here...
For a meter id like "124123ABC231" treat it as text rather than a numeric value. That keeps letters, leading zeros, and formatting intact. was on the right track: use a string-type container so the value can be stored, printed and validated without trying to do arithmetic on it.
Choice depends on your toolchain. In plain C you will use a fixed buffer and must explicitly guard its length and the terminating NUL; in C++ a string class handles memory for you and is easier to work with. Note that classic Turbo C/Turbo C++ is old and its standard library support is limited compared with modern compilers, so std::string and newer library conveniences may not work the same there — consider moving to a modern compiler if possible (Turbo C - Wikipedia, std::string reference).
Practical tips: decide a maximum length and enforce it; trim surrounding whitespace; normalize case if you need consistent comparisons; reject or flag any character that is not a letter or digit (use character-class tests such as isalnum for validation) — see isalnum. Avoid deprecated unsafe input functions; prefer input routines that let you limit how many characters are read (gets was removed for safety reasons). These checks make the data predictable and protect against overflows on older compilers.
Jump to Post— Ancient Dragon 5,243a character array or std::string
a character array or std::string
can you give a sample how to do it...?
char mnumber[255];
printf("Enter an item number\n");
fgets(mnumber,sizeof(mnumber), stdin);
if( mnumber[strlen(mnumber)-1] == '\n')
mnumber[strlen(mnumber)-1] = '\0';
printf("Meter number is: %s\n", mnumber); Or if you want the c++ version
std::string mnumber;
cout << "Enter an item number\n";
getline(cin,mnumber);
cout << "Meter number is: " << mnumber << '\n'; We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.