Reading text without using standard libraries

This is a discussion on Reading text without using standard libraries within the C Programming forums, part of the General Programming Boards category; Any idea how I might be able to read text from user input without using any standard C libraries? (no ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    Reading text without using standard libraries

    Any idea how I might be able to read text from user input without using any standard C libraries? (no scanf allowed)

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    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

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Use any non-standard input functions specific to your OS/Compiler.

    /me wonders at the perversity of specifically avoiding standard routines.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    2
    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. dont 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.

  5. #5
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    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

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.

  7. #7
    Cached User mako's Avatar
    Join Date
    Dec 2005
    Location
    Germany.Stuttgart
    Posts
    69
    Quote Originally Posted by filker0
    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.
    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*.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading text files on the internet
    By Mavix in forum C# Programming
    Replies: 8
    Last Post: 06-20-2007, 05:38 AM
  2. Reading text file and structuring it..
    By Killroy in forum C Programming
    Replies: 20
    Last Post: 11-19-2004, 07:36 AM
  3. reading integers into arrays from text files
    By c_beginner in forum C Programming
    Replies: 6
    Last Post: 08-05-2004, 11:42 AM
  4. Reading Text files
    By AmazingRando in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2003, 08:30 PM
  5. Reading Tab Separted Text files
    By Cathy in forum C Programming
    Replies: 1
    Last Post: 02-15-2002, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21