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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:32:21+00:00 2026-05-30T20:32:21+00:00

I want to parse a text file in a C program. The file contains

  • 0

I want to parse a text file in a C program. The file contains data that is likely to be:

block1=
{
    a="some text with space and double quota"    
    b=random text    
    c=random text    
    d=random text    
    e=random text    
    f="number"    
    g=number    
}

block2=
    {
        a="some text with space and double quota"    
        b=random text    
        c=random text    
        d=random text    
        e=random text    
        f="number"    
        g=number    
    }

There may be n number of blocks, I want to create list of elements (“a” elements of each block) , for that what should I do? Is there any parsing API for text file in C?

  • 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-30T20:32:22+00:00Added an answer on May 30, 2026 at 8:32 pm
    #include <stdio.h>
    #include <string.h>
    
    typedef struct block {
        char head[8];
        char braze[2];
        char a[46];
        char b[18];
        char c[18];
        char d[18];
        char e[18];
        char f[15];
        char g[13];
        char close_braze[2];
    } block;
    
    int main () {
        int i, ret;
        char a_elm[10][50];
        FILE *fp;
        block blk[10]; //use a specific number if you know. or go for linked list
    
        fp = fopen ("one.txt","r");
    
        for (i = 0; i < 11; i++) {
            ret = fread ((void *) &blk[i], sizeof (block), 1, fp);
            if (!ret)
                break;
        }
        fclose (fp);    
    
        for (ret = i, i = 0; i < ret; i++) {
            strncpy (a_elm[i], blk[i].a, 46);
            a_elm[i][46] = '\0';
            printf ("%s\n", a_elm[i]);
        }
    
        return 0;
    }
    

    For fixed format code, fread can be used as above or you have to use fscanf with some string functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a large text file so that it breaks into a
I have a text file that I parse each month and insert the data
I want to parse the html file, pdf file, csv file and text file.Now
I want to parse an Apache access.log file with a python program in a
I have text file with several thousands lines. I want to parse this file
I have a text file with Tag - Value format data. I want to
I have to write a program that read from a file that contains the
I have a text file in the following url. http://hosted.stats.com/ifb2009/data.asp?file=en/chlg_standings.txt I want to parse
I'm trying to parse a text file that has a heading and the body.
I want to parse a text file to get what I want and create

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.