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

  • SEARCH
  • Home
  • 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 8166369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:50:28+00:00 2026-06-06T19:50:28+00:00

i`ve been trying o use fscanf to read the an input file on my

  • 0

i`ve been trying o use fscanf to read the an input file on my application.

This is the input file

3
Process#1 - 2Kb
3
exec 20

io 5

exec 50

Process#2 - 8Kb

1

exec 100

Process#3 - 8Kb

4

exec 50

io 50

exec 50

io 50

First of all i want to read the First “3”, which i am having no problems doing so.

After that, i will need to read the information after the # (which is 1) and the number right after the “kb” string (which is 2).

Why is this fscanf failing to do so ?

fscanf(inputFile, "Process#%d - %dKb", &id, &mem ); 

How can i do it ?

Thanks in advance

  • 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-06-06T19:50:30+00:00Added an answer on June 6, 2026 at 7:50 pm

    Probably because the newline left behind after the 3 is not being recognized by the P in Process.

    This is why many people avoid scanf(); it is usually simpler to use fgets() or a related function (but not gets()!) and then use sscanf().


    Demo code

    Notice the rigorous checking of the return from scanf(). If you don’t do that, you will not know when things have gone wrong. Note that the check is for the correct number of conversions, too.

    #include <stdio.h>
    int main(void)
    {
        int i;
        int id;
        int mem;
    
        if (scanf("%d", &i) != 1)
            printf("oops!\n");
        /* With    space - reads past newline on first line */
        /* Without space - prints 'thank goodness!' */
        if (scanf(" Process#%d - %d", &id, &mem) != 2)
            printf("thank goodness!\n");
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi ive been trying to use System.Security.Cryptography to encrypt and decrypt a file but
I've been trying to use this code in some XSS research I am conducting.
I've been trying to use Dart's noSuchMethod() , but this code noSuchMethod(InvocationMirror invocation) {
I've been trying to use WF in my ASP.NET application (actually, it's ASP.NET MVC
I've been trying to use the WPF toolkit in a WPF application that I'm
I have been trying to use an ajax-style file upload component (like the dojox
I have been trying to use PHPUnit to test an application. I have it
I've been trying to use vim to simplify writing latex. To this end, I
I've been trying to use the Java SAX parser to parse an XML file
I've been trying to use mongo with some data imported, but I'm not able

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.