Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:57:21+00:00 2026-05-29T05:57:21+00:00

I have actually a small problem with file i/o and finding the right algorithm

  • 0

I have actually a small problem with file i/o and finding the right algorithm to read the data correctly. The problem is, that the “header” could look a little bit different from each file.

For example:

File 1.
500 500
100
Binary

File 2.
500

d500
100
Binary

File 3.
   500
500

100
Binary

File 4.
500
500       100
Binary

…

I’m interested to get the 3 numeric values. I tried it with fgets and scanf and also with fscanf… and so one.
But I find at every try a way, where I’m not able to get the values.

Dose someone have some ideas, who I could get the values in every case?

Edit

/* Jump over the identification and comment strings. */
        fseek(in, 3, SEEK_SET);
        do
        {
            fgets(line, PREAMBLE, in);
        } while(strncmp(line, "#", 1) == 0);

        /* Save the information in the structer. */
        sscanf(line, "%u %u", &imginf.width, &imginf.height);
        fgets(line, PREAMBLE, in);
        sscanf(line, "%u", &imginf.depth);
        return imginf;

This works for example:

File
500 500
100
Binary

Solution

Her is the interesting part of the code. Now I think I get every value. Maybe the code looks a little bit smelly, I haven not made sure that the code is clean.

  while (a[2] == 0 ){
        fgets(line, 255, in);
        i = 0;
        while (line[i] != '\0') {
            if ((line[i] < '0') || (line[i] > '9')) {
                i++;
            }
            else {
                while ((line[i] >= '0') && (line[i] <= '9')) {
                    buffer[j] = line[i];
                    j++;
                    i++;   
                }
                j = 0;
                a[k] = atoi(buffer);
                printf("%d\n", a[k]);
                strcpy(buffer, "");  
                k++;
            }
        }
    }

Greetz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:57:21+00:00Added an answer on May 29, 2026 at 5:57 am

    Read character-by-character and parse the input yourself.

    Something like

    do 3 times {
        ignore anything not a digit
        read number digit-by-digit
    }
    // input is now pointing to the 2nd non-digit
    // just after the last digit of the 3rd number
    // the 1st non-digit should be saved in the variable you used in the loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this small xls file that's actually a tab-delimited txt file. In
I have a small project that I need to compile. I have one header
Can you recommend a single downloadable video ( one that you have actually watched
I actually have two questions regarding the same problem but I think it is
I actually have right now two questions: 1) What font faces are preferred for
I actually have two questions regarding exception/error handling in the iPhone app that I
I actually have 2 queries: How do I display the data of a variable
I have heard that it's best not to actually have any html in your
Just a newbie with iPhone development.. I just have a small problem but huge
I have a small project that builds a number of targets from the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.