Thread: String to int

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    2

    String to int

    I have a file with the following entries:

    ;LAYER:1CRLF
    ...
    ...
    :LAYER:1047CRLF
    (CRLF is carriage return line feed)

    How do I parse the string to set a int to the LAYER value noting the string character changes based on the number of digits?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Use fgets() to read each line.

    Use sscanf to parse each line.

    Say for example
    sscanf(buff,":LAYER:%d",&number);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    2
    Quote Originally Posted by Salem View Post
    Use fgets() to read each line.

    Use sscanf to parse each line.

    Say for example
    sscanf(buff,":LAYER:%d",&number);
    Great solution. There are a great number of standard c libraries I have yet to learn. Thanks for being so gracious!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-01-2013, 10:11 PM
  2. Replies: 1
    Last Post: 04-27-2013, 04:36 AM
  3. Replies: 22
    Last Post: 07-28-2011, 01:26 PM
  4. Replies: 7
    Last Post: 06-16-2011, 06:21 PM
  5. Replies: 1
    Last Post: 10-31-2005, 11:36 AM

Tags for this Thread