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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:54:43+00:00 2026-05-17T17:54:43+00:00

I am trying to extract data from a xml file, get rid of the

  • 0

I am trying to extract data from a xml file, get rid of the xml tags, and store the values in a txt file (tab delimited format) using C. I was able to extract and manipulate the string but I am unable to paste the string to the txt file in a tab delimited format. Instead of getting a txt file that should read like:

x.xxxxxxx        x.xxxxxxxx    x.xxxxxxxx

I get a file that reads like

x.xxxxxxx

      x.xxxxxxx
      x.xxxxxxx

I think this is happening due to the way I am manipulating the string from x.xxxxxxx format to x.xxxxxxx format. As a beginner, I’m not entirely sure how to get around this problem. What can I do to fix it?

Thanks in advance.

#include <string.h>
#include <stdio.h>
#include <stddef.h>

#define MAX 10000

int main (int argc, char *argv[]){
    FILE *fp;
    char str[MAX];
    char *c[MAX];

    char *xcoor[MAX];
    char *ycoor[MAX];
    char *zcoor[MAX];
    char *z;
    int i =0;

    if((fp = fopen("550.txt", "r"))==NULL){
        printf("Cannot open file.\n");
        exit(1);
    }

    while(!feof(fp)) {
        while(fgets(str, sizeof str, fp)) {
            *(c+i)=strdup(str);
            i++;
        }
    }
    fclose(fp);
    int a = 0;

    for(i=5;i<1700;i=i+17){
        xcoor[a]=c[i];
        a++;
    }

    int b = 0;
    for(i=6;i<1700;i=i+17){
        ycoor[b]=c[i];
        b++;
    }

    char letterx = 'x';
    char lettery = 'y';
    char arrow1 = '<';
    char arrow2 = '>';
    char slash = '/';

    for (i=0;i<100;i++){
        z = *(xcoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == letterx)
            strcpy(z+g, z+g+1);
        }
        *(xcoor+i)=z;        
    }

    for (i=0;i<100;i++){
        z = *(xcoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == arrow1)
            strcpy(z+g, z+g+1);
        }
        *(xcoor+i)=z;    
    }

    for (i=0;i<100;i++){
        z = *(xcoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == arrow2)
            strcpy(z+g, z+g+1);
        }
        *(xcoor+i)=z;        
    }

    for (i=0;i<100;i++){
        z = *(xcoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == slash)
            strcpy(z+g, z+g+1);
         }
        *(xcoor+i)=z; 
    }

    for (i=0;i<100;i++){
        z = *(ycoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == lettery)
                strcpy(z+g, z+g+1);
        }
        *(ycoor+i)=z;        
    }

    for (i=0;i<100;i++){
        z = *(ycoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == arrow1)
                strcpy(z+g, z+g+1);
        }
        *(ycoor+i)=z;    
    }

    for (i=0;i<100;i++){
        z = *(ycoor+i);
        int g = 0;
         for(g;g<strlen(z);g++){
            if(z[g] == arrow2)
                strcpy(z+g, z+g+1);
        }
        *(ycoor+i)=z;        
    }

    for (i=0;i<100;i++){
        z = *(ycoor+i);
        int g = 0;
        for(g;g<strlen(z);g++){
            if(z[g] == slash)
                strcpy(z+g, z+g+1);
        }
        *(ycoor+i)=z;        
    }

    FILE *agentfile;
    agentfile = fopen("name.txt", "w");
    for(i=0;i<100;i++){
        fprintf(agentfile, "%s    %s", *(xcoor+i),    *(ycoor+i));
    }
    fclose(agentfile);
    printf("I'm happy that the program ended fine");

    return 0;
}
  • 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-17T17:54:43+00:00Added an answer on May 17, 2026 at 5:54 pm

    fgets returns most a ‘\n’, you must remove that:

    while(!feof(fp)) {
        while(fgets(str, sizeof str, fp)) {
            *(c+i)=strdup(str);
            i++;
        }
    }
    

    better:

    while( fgets(str, sizeof str, fp) ) {
      if( strchr(str,'\n') )
         *strchr(str,'\n')=0;
      *(c+i)=strdup(str);
      i++;
    }
    

    strdup is not ANSI C.

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

Sidebar

Related Questions

I'm trying to extract data from a data file that's tab-delimited (in some parts),
I am trying to extract data from XML file and save it my C#
I am trying to extract data from XML. I generated C# classes using XSD
I am trying to extract some data from XML but when I execute the
I am trying to extract a table of values from an excel (2003) spreadsheet
I'm trying to parse a html page and extract 2 values from a table
We have an architecture where we use SSIS to extract data from XML batch
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
I am attempting to extract all data from a file with one regex expression.
While trying to extract data from a view by joining it with two other

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.