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 7683033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:42:15+00:00 2026-05-31T18:42:15+00:00

I am parsing a file for particular keyword matching by C program, here is

  • 0

I am parsing a file for particular keyword matching by C program,
here is my sample code…

#include <stdio.h>

int main() { 

    FILE *infile = fopen("Somefile.txt", "r");

    char buffer[256];
    char value[128];

    while (fgets(buffer, sizeof(buffer), infile))
        if (1 == sscanf(buffer, " x = %s", value))
            printf("Value = %s\n", value);
    return 0;
}

Somefile.txt

some junk
#a comment
a = 1 ; a couple other variables.
b = 2
x = 3
 x = 4
x=5
x = Hi hello

Output:

Value = 3
Value = 4
Value = 5
Value = Hi

Problem : when x contain the value like “Hi Hello”, then it just parsing “Hi” only, I want to parse whole value of x without loosing space.

please suggest me solution for it.

Thanks.

  • 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-31T18:42:16+00:00Added an answer on May 31, 2026 at 6:42 pm

    In this line of your code:

    if (1 == sscanf(buffer, " x = %s", value))
    

    %s means to read in one word.

    If you want to read in the rest of the line, use %[^\n]s like this:

    if (1 == sscanf(buffer, " x = %[^\n]s", value))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
I need some php code for parsing raw apache logs. In particular, I want
Suppose I am parsing a fixed-width file: file_format = {'year' : (0, 3, int),
I am having trouble parsing this particular line using sed: /media/file/1.bmp app:Stuff I want:
I'm parsing a file that is set up like so: <blah-name name=Turkey> <blah-city name=Test/>
I'm parsing some file with XmlPullParser in Android Everything goes fine except for some
I have student.xml file and am parsing this file using SAX Parser and now
I have developed a file parsing application on the android platform. How do I
Perl is really good for writing the kind of string/file parsing programs that I
I'm working in C#/.NET and I'm parsing a file to check if one line

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.