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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:15:21+00:00 2026-05-27T02:15:21+00:00

XXX—-Yep, its a Homework problem, but yea I’m stuck. Why doesn’t this print out

  • 0

XXX—-Yep, its a Homework problem, but yea I’m stuck. Why doesn’t this print out the elements of the array? Please help—XXX

Ok, we got the printing out part figured out. Thank you so much. Now the problem is the only the first character(s) before the space delimiter gets put into the array. I need all the words or characters to be set into the array.

int main(int argc, char** argv) {

    int size = 0;
    char **array = malloc(0); //malloc for dynamic memory since the input size is unknown
    static const char filename[] = "input.txt";
    FILE *file = fopen(filename, "r");
    if (file != NULL) {
        char line [ 128 ]; 

        char delims[] = " ";
        char *result = NULL;
        while (fgets(line, sizeof line, file) != NULL)  {
            result = strtok(line, delims); //separate by space
            size++;
            array = realloc(array, size * sizeof (char*)); //declare array with unknown size
            array[size - 1] = result;

        }
        fclose(file);
    } else {
        perror(filename);
    }
    return 0;
    printf(array); //print array???
    return (EXIT_SUCCESS);
}
  • 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-27T02:15:21+00:00Added an answer on May 27, 2026 at 2:15 am

    Please check this code. I believe that it does what you are expecting.

    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    
    int main(int argc, char** argv) 
    {
        int size = 0;
        int i;
        char **array = malloc(0); //malloc for dynamic memory since the input size is unknown
    
        static const char filename[] = "input.txt";
        FILE *file = fopen(filename, "r");
    
        if (file != NULL) 
        {
            char line [ 128 ]; 
    
            char delims[] = " ";
            char *result = NULL;
    
            while (fgets(line, sizeof line, file) != NULL)
            {
                result = strtok(line, delims); //separate by space
    
                while( result != NULL ) 
                {                       
                    size++;
    
                    array = realloc(array, size * sizeof (char*)); //declare array with unknown size
                    array[size - 1] = malloc(100 * sizeof(char));  // allocate memory for 100 chars
                    strcpy(array[size - 1], result);               // copy the result
    
                    result = strtok( NULL, delims );
                }
            }
    
            fclose(file);
        } 
        else 
        {
            perror(filename);
        }
    
        // return 0; 
    
        for (i = 0; i < size; i++)
        {
            printf("array[%d] = %s\n", i, array[i]);
        }
    
        // printf(array); //print array???
    
        return (EXIT_SUCCESS);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normaly i would do a delete * from XXX but on this table thats
This code used to return my local ip address as 192.xxx.x.xxx but now it
Whenever I do: xxx = [NSImage imageNamed:@Package.png]; xxx loads but it's width and height
We've reviewed XXX and determined that we cannot post this version of your iPhone
am startservice com.xxx/.service.XXXService i can start a service through the command above , but
I'm querying Solr like this: http://XXX.xx.xx:xxx/solr/select?q=name:(pizza)&fq=locationid:6050 OR _query_:{!bbox}&sfield=location&pt=34.0211224, -118.39646&d=8 I am searching for records
I am reading xml from xxx URl but i am getting error as Root
I want to open a xxx.txt file kept on desktop of my Computer but
This is the code: package com.XXX; public final class Foo { private Foo() {
You know sometimes XXX person releases some open source executable. But it has the

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.