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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:19:42+00:00 2026-06-12T15:19:42+00:00

I really need to know how to fix this. I have a file that

  • 0

I really need to know how to fix this.

I have a file that is read and I store the strings from the file into an array that is passed as an argument, but I can’t figure out how to make it work.

When I do print the content of the array it says null.
So how do I pass a multi-dimensional array of strings to readfiles() and make it save the strings in the array passed as parameter, each string in one position?

Thanks for the help.

#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdio.h>
#include <strings.h>

#define max_chars_string 10000
#define n_strings 100


int main(int argc, char **argv)
{
    char *filename;
        char strings_hashes[n_strings][max_chars_string];
        char * pointer_string = &strings_hashes[0][0]; 
    int n_lines;
    int i = 0;




    filename = (char*)malloc(strlen(argv[1])*sizeof(char));

    if(argc !=3){
        fprintf(stderr, "Usage : %s [text_file] [cores]",argv[0]);
        exit(0);
    }

    strcpy(filename,argv[1]);
    read_lines(filename,pointer_string); 
    for(i = 0; i<n_lines;i++){
        printf("%s \n",strings_hashes[i][max_chars_string]);
    }

  return 0;
}

void read_lines(char * filename, char *pointer){ 
    FILE *fp;
    char str[max_chars_string];
    int i =0;


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

    while(!feof(fp)) {
        while(fgets(str, sizeof str, fp)) {
           strcpy(pointer, str);
           printf("%s", str);
           pointer++;
           i++;
      }

  }
  fclose(fp);
}
  • 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-12T15:19:44+00:00Added an answer on June 12, 2026 at 3:19 pm

    Change

    void read_lines(char * filename, char *pointer){ 
    

    to

    void read_lines(char * filename, char (*pointer)[max_chars_string]){ 
    

    (pointer‘s type needs to be “pointer to array of max_chars_string chars”. When using pointers to access multidimensional arrays, the pointer type needs to know the all the dimensions except for the outermost one, so that it knows how far to skip along when incremented.)

    Change

    strcpy(pointer, str);
    

    to

    strcpy(*pointer, str);
    

    Now call it as

    read_lines(filename,strings_hashes);
    

    (This is equivalent to the following, which may be clearer:)

    read_lines(filename,&string_hashes[0]);
    

    Finally, you want to print a string not an individual character, so use

    printf("%s \n",strings_hashes[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't really know XSL but I need to fix this code, I have
I have a really big log file (9GB -- I know I need to
I have this function in my program that converts integers to strings: QString Stats_Manager::convertInt(int
So I have this pretty large XML file (40MB) that I'll have to repeatedly
Well, I know absolutely nothing about the subject, so I really need help. I
I am relatively new to grails and need to know something really basic. Right
Hey, I'm really stuck with my project here... I need to know when any
I dont really know how to explain exactly what function i need but ill
Really need just some guidance : Topological sort by arcs definition (from my question)
I really need help with this last part of my program. I need to

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.