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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:32:14+00:00 2026-05-27T18:32:14+00:00

this is my second question as i’ve had trouble with the first one due

  • 0

this is my second question as i’ve had trouble with the first one due to this problem.
I have a file which i have to read using the read() statment, no no fget() or fread() etc
i use the line.

read(fileRead, buffer, blocksize);

where as you know fileRead is my filedescriptor, buffer is an unsigned char and blocksize is the size of buffer (i chose 32);
my problem is i have a loop which runs until the file ends and takes a buffer of the file (32) and i need to put that into a string.

So i was wondering if you could help me with the line of code which would take the buffer and append it to a string (not 2D array, this won’t be good)
I have tried

openCopyClose(int argc, char ** argv)
{
    int i=0,j=0, k=0, count = 0;
    size_t blocksize = 32;
    char fromFile[256], newFile[1000][100], string[100000];
    int fileRead;
    unsigned char buffer[blocksize];
    ssize_t status;

    strcpy(fromFile, argv[1]);

    fileRead = open(fromFile, O_RDONLY);  // open for reading

    status = 99;
    while (status > 1)        //while not EOF or error
    {
        status = read(fileRead, buffer, blocksize);
        strcpy(newFile[i], buffer);

        for(count = 0; count<= 32; count++)
        {
            buffer[count] = 0;
        }
        i ++;                   

        if(status < 0)
        {
            printf("oops2\n");
            exit(1);
        }

    }
    printf("\n");

    for(j = 0; j < i; j++)
    {
        printf("%s", newFile[j]);
    }          
    close(fileRead);

}

But this will not work when i try to strtok it to put it in a structure. I need that file into one string using read() any ideas?

my code for the strtok afterwards will need to look something like this

struct processStruct processes[700];
while(count < 701)
{

    processes[count].processNumber = strtok(newFile[0], " \n");
    processes[count].quanta = atoi(strtok(NULL, " \n"));
    processes[count].priority = atoi(strtok(NULL, " \n"));

    count ++;
}

thank you

  • 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-27T18:32:14+00:00Added an answer on May 27, 2026 at 6:32 pm

    i solved how to put the File into a string, it was relatively simple, i’m surprised i missed it

    for(k =0; k < sizeof(buffer); k++)
    {
        newFile[i] = buffer[k];
        i++;
     }
    

    and now to put it in the struct…..

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

Sidebar

Related Questions

This is my second question on Bamboo ( My First One ). My understanding
In my validation class I have this: $fields['a_1'] = 'First Question'; $fields['a_2'] = 'Second
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
I hope it's the heat, this is the second question today and it's one
This is my second question today and the first was an incredibly stupid question
First question: Say I have using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string
Is my second question on this topic today but on the previous one it
Apologies for making this my second Z80 DAA question - I have pretty much
I have asked this question in cstheory too I have a form distribution problem.
I have read this question and found its answer to be useful to check

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.