Any idea how I might be able to read text from user input without using any standard C libraries? (no scanf allowed)
Any idea how I might be able to read text from user input without using any standard C libraries? (no scanf allowed)
Are you allowed to use read()?
I'm assuming that what you're looking for is no use of stdio (standard IO).
Insert obnoxious but pithy remark here
Use any non-standard input functions specific to your OS/Compiler.
/me wonders at the perversity of specifically avoiding standard routines.
This is the actual challenge:
Write an optimized C program to convert a base 16 number to its base 10 equivalent, without using the standard C libraries, i.e. don’t use scanf(“%x”). The program should allow the user to input the number. State any assumptions you made when writing the program. Use 23DA as a test number.
Are you allowed to take the argument on the command line?
Since strtoul() is "standard library", I suspect that your instructor wants you to do the hex to decimal conversion yourself. So I'd suggest writing a function with a name like "hextolong()' that takes a string of hexidecimal digits and returns an unsigned long integer with the value of that hex string.
I will leave the code up to you.
Insert obnoxious but pithy remark here
It sounds like you are allowed to use standard C libraries to get the text input. Your instructor just doesn't want you using any standard libraries to do the conversion. Use fgets() to read in the text, then perform the conversion yourself.
atoi(hex_holding_string,Int_to_b_stored_in, 10); /* converts whatever ehxadec (or other value) is stored in the string into a base 10 value. You could justaswell change it to bae 2*.Originally Posted by filker0
atoi is also a standard function. filker0 hit the nail on the head. The goal it seems is to write your own conversion function, and not find any way around it using some standard conversion function.
Quzah.
Hope is the first step on the road to disappointment.