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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:26+00:00 2026-05-27T17:30:26+00:00

i’m pretty new to forums so i hope i don’t mess up. I have

  • 0

i’m pretty new to forums so i hope i don’t mess up.
I have a program that reads from a file, so far it puts the file into a 2D char array. I now need to strtok the 2D ‘string’ and place each part into a struct

here is the code

struct processes                 
{ 
    char processNumber[20]; 
    int quanta; 
    int priority; 
}process; 

and

   int readSave(int argc, char ** argv)
{
int i,j,k,count;
size_t blocksize = 16;
char originalFile[256], newFile[1000][20];
int fileDes;
ssize_t status;
unsigned char buffer[blocksize];


strcpy(originalFile, argv[1]);

fileDes = open(originalFile, O_RDONLY); // open for reading

i=0;
status = 99;
while(status > 0 )  // while no error
{
    status = read(fileDes, buffer, blocksize);
    strcpy(newFile[i],buffer); //line 71

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

    if(status < 0)
    {
        printf("\nERROR\n");
        exit(6);
    }   
}

//remove later
for(j = 0; j < i; j++) // prints out string to make sure it was input properly
{
    printf("%s", newFile[j]);
}

printf("\n");
close(fileDes);

//Don't know how to carry on

}

I hope you can help because i’m lost
EDIT
struct processStruct processes[7000];
while(newFile != NULL)
{
strcpy(processes[count].processNumber, strtok(newFile[count], ” \n”));
processes[count].quanta = atoi(strtok(NULL, ” \n”));
processes[count].priority = atoi(strtok(NULL, ” \n”));

    count ++;
}

i changed the struct and input given by @Igor but when i run it, i get a segmentation fault and when i compile with -Wall i get
readtostring.c: In function ‘readSave’:
readtostring.c:71:3: warning: pointer targets in passing argument 2 of ‘strcpy’ differ in signedness [-Wpointer-sign]
/usr/include/string.h:128:14: note: expected ‘const char * restrict’ but argument is of type ‘unsigned char *’

  • 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-27T17:30:27+00:00Added an answer on May 27, 2026 at 5:30 pm

    Issue 1:

    Seems like you should do strtok(newFile[something], " \n") and not strtok(newFile, " \n").
    And don’t forget to do something++ in each iteration.


    Issue 2:

    You can’t strcpy to int. Try instead:

    process[something].quanta = atoi(strtok(NULL, " \n"));
    process[something].priority = atoi(strtok(NULL, " \n"));
    

    Issue 3:

    process is a struct and not array of structs, so you can’t do process[something]. Did you mean to create an array of structs: processes process[20];

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

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a view passing on information from a database: def serve_article(request, id): served_article

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.