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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:04:12+00:00 2026-06-12T12:04:12+00:00

I’ve been struggling with this simple linux shell for hours now, and for some

  • 0

I’ve been struggling with this simple linux shell for hours now, and for some reason I just can’t get the most basic thing working correctly. Something is seriously messed up with how I handle my input or something, because one example of how this shell doesn’t work is the mkdir command. It randomly won’t create a random directory I never tried to create, and every time I do create a directory it manages to create some other ones with random names I obviously didn’t create. Something is messed up and I just have no clue, because I’ve been outputting my final argument array and it looks fine from there. Can someone please take a look at this for me.

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


int main(int argc, char *argv[]){
while(1){
    char line[100], *temp, *split[15];
    int child_id;
    printf("$ ");
    fgets(line, sizeof(line), stdin);
    line[strlen(line)-1] = '\0';

    temp = strtok(line, " ");
    int i = 0;
    while(temp != NULL){
        split[i] = temp;
        temp = strtok(NULL, " ");
        i++;
    }

    char *args[i];
    int j;
    for(j = 0; j < i; j++){
        args[j] = split[j];
        printf("%s\n", args[j]);
    }
    child_id = fork();
    if(child_id == 0){
        execvp(args[0], args);
        exit(0);
    }else{
        wait(&child_id);
    }


  }

}
  • 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-12T12:04:15+00:00Added an answer on June 12, 2026 at 12:04 pm

    When using execvp(), the final element of the args array must be NULL (this tells the kernel where the list of command line arguments ends).

    You should be able to do this by adding split[i] = NULL; after the strtok() loop (oh, and no need to copy the array to args as mentioned in the comment above, just use split).

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.