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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:31:58+00:00 2026-06-02T01:31:58+00:00

Still in the fiddling stage with C. Not sure what I’m doing wrong here

  • 0

Still in the fiddling stage with C. Not sure what I’m doing wrong here but I think it has to do with pointers. Anyway. I’m trying to read in and parse a tab-delimited text file into a 2D array. The actual array is 6109 x 14, I allotted a bigger pointer array.

FILE *in = fopen("afile","rt");
// read the first line from the file
char line[2000];
int x=0;
int y=0;
char *result[7000][14];
char *curResult;
char delim[]= "\t";

while (fgets(line, 2000, in) != NULL) {
    printf("LINE IS %s\n",line);
    curResult=NULL;
    curResult = strtok(line,delim);
    y=0;
    while( curResult != NULL ) {
        result[x][y]= curResult;
        curResult = strtok( NULL, delim );
        y++;
    }
    x++;
}

//print a random line to check 
for(int i=0; i<10; i++)
    printf("%s\n", result[50][i]);

The line I printed at the bottom which should be the 50th line prints the last line of the text file. I tried this with different numbers instead of 50 but they all print the same thing.

EDIT: afile looks like this:

  instance_id   batch_id    cmap_name   INN1    concentration (M)   duration (h)    cell2   array3  perturbation_scan_id    vehicle_scan_id4    scanner vehicle vendor  catalog_number  catalog_name
1   1   metformin   INN 0.00001 6   MCF7    HG-U133A    EC2003090503AA  EC2003090502AA  HP GeneArray Scanner    medium  Sigma-Aldrich   D5035   "1,1-dimethylbiguanide hydrochloride"
2   1   metformin   INN 0.00001 6   MCF7    HG-U133A    EC2003090504AA  EC2003090502AA  HP GeneArray Scanner    medium  Sigma-Aldrich   D5035   "1,1-dimethylbiguanide hydrochloride"
3   1   metformin   INN 0.0000001   6   MCF7    HG-U133A    EC2003090505AA  EC2003090502AA  HP GeneArray Scanner    medium  Sigma-Aldrich   D5035   "1,1-dimethylbiguanide hydrochloride"
4   1   metformin   INN 0.001   6   MCF7    HG-U133A    EC2003090506AA  EC2003090502AA  HP GeneArray Scanner    medium  Sigma-Aldrich   D5035   "1,1-dimethylbiguanide hydrochloride"
21  2   phenformin  INN 0.00001 6   MCF7    HG-U133A    EC2003091104AA  EC2003091102AA  HP GeneArray Scanner    medium  Sigma-Aldrich   P7045   phenformin hydrochloride
22  2   phenyl biguanide        0.00001 6   MCF7    HG-U133A    EC2003091105AA  EC2003091102AA  HP GeneArray Scanner    medium  Sigma-Aldrich   P19906  1-phenylbiguanide hydrochloride
23  2   valproic acid   INN 0.001   6   MCF7    HG-U133A    EC2003091106AA  EC2003091102AA  HP GeneArray Scanner    medium  Sigma-Aldrich   P4543   2-propylpentanoic acid
61  2a  metformin   INN 0.00001 6   MCF7    HG-U133A    EC2003091103AA  EC2003091102AA  HP GeneArray Scanner    medium  Sigma-Aldrich   D5035   "1,1-dimethylbiguanide hydrochloride"
  • 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-02T01:31:59+00:00Added an answer on June 2, 2026 at 1:31 am

    Imagine line is a big box where you can put a bunch of letters.
    That’s what you do with fgets().

    Next you point to specific letters inside that box.

    Next you replace the contents of the box (another fgets() to the same variable line) and the pointers, of course still point to the same box, but now to the new letters.

    You need to copy the characters (with strcpy(), check that you have enough space first) somewhere inside your loop.

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

Sidebar

Related Questions

Still 'diving in' to Python, and want to make sure I'm not overlooking something.
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't
Still having a great time fiddling with aChartEngine, but I have come to a
So been fiddling around with this for a while now but still no luck.
still trying to find where i would use the yield keyword in a real
Still trying to get the navigation control of a new site working the way
Still can't get this working...Rails 3.1.3, Ruby 1.9.2 on Heroku's Cedar Stack. Trying to
I am currently still fiddling with our msbuild & deployment script and one of
I'm still learning the ropes with PHP & MySQL and I know I'm doing
Still learning a lot.. But basically finally finished my website, but now I'm failing

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.