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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:22:15+00:00 2026-06-14T13:22:15+00:00

I am trying to store a string data file into a multi-dimensional array using

  • 0

I am trying to store a string data file into a multi-dimensional array using C.My sample data looks as below.I am thinking to use below char declaration for storing my data.Please kindly advise me if there is any other method.

char *array[6][10];

53,v42,p11,51097,310780,ok
56,v45,p11,260,1925,ok
68,v42,p11,51282,278770,ok
77,v50,p11,46903,281485,ok
82,v46,p12,475,2600,ok
84,v48,p12,433,3395,ok
96,v49,p14,212,1545,ok
163,v50,p20,373819,1006375,ok
204,v50,p26,36917,117195,ok
241,v70,p33,21777,91360,ok
  • 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-14T13:22:17+00:00Added an answer on June 14, 2026 at 1:22 pm

    I hope this sample program will help you to address your issue. I used structure and sscanf. This is the nice way to address this issue.

    #include <stdio.h>
    struct data
    {
        char date[100];
        char state[100];
        char profit[100];
        char revenue[100];
    };
    
    int main()
    {
          char line[4096] = {'\0'};
          char t1[100], t2[100], t3[100], t4[100];
          struct data d[2];
          int i = 0;
          while(fgets(line, 4096, stdin) != NULL) {
                  sscanf(line, "%[^','],%[^','],%[^','],%s", &t1, &t2, &t3, &t4);
                  strcpy(d[i].date, t1);
                  strcpy(d[i].state, t2);
                  strcpy(d[i].profit, t3);
                 strcpy(d[i++].revenue, t4);
         }
         i = 0;
         while(i<2){
                 printf("%s %s %s %s\n", d[i].date, d[i].state, d[i].profit, d[i].revenue);
                 i++;
         }
     } 
    

    $> a./exe < file

    $> cat file

    12/2/2012,TN,1200,14000
    12/3/2012,KA,2333554,424
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to store a string into an integer array with the following
I am trying to read contents of a file using string tokenizer and store
I'm trying to store data from an input file into a series of objects,
I'm trying to store data in the following fashion with a string as the
I'm trying to use Sencha Touch 2 to load a local json file into
I am trying to get 2D array data from a Java properties file and
I am currently trying to write a program to store data about people into
I'm trying to store more than one sha256 hashed strings as a single string
I'm trying to store today's date in a sqlite table as a string in
I am trying to extract some part of string and store it to hbase

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.