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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:05:50+00:00 2026-05-24T06:05:50+00:00

I am completely newbie in C. I am trying to do simple C function

  • 0

I am completely newbie in C.
I am trying to do simple C function that will split string (char array).

The following code doesn’t work properly because I don’t know how to terminate char array in the array. There are to char pointers passed in function. One containing original constant char array to be split and other pointer is multidimensional array that will store each split part in separate char array.

Doing the function I encountered obviously lots of hustle, mainly due to my lack of C experience.

I think what I cannot achieve in this function is terminating individual array with ‘\0’.
Here is the code:

void splitNameCode(char *code, char *output);

void splitNameCode(char *code, char *output){

    int     OS = 0; //output string number
    int     loop;
    size_t  s = 1;

    for (loop = 0; code[loop]; loop++){
        if (code[loop] == ':'){ 
            output[OS] = '\0'; // I want to terminate each array in the array
            OS ++;
        }else {
            if (!output[OS]) {
                strncpy(&output[OS], &code[loop], s);
            }else {
                strncat(&output[OS], &code[loop], s);
            }
        }
    }
}

int main (int argc, const char * argv[]) {

    char output[3][15];
    char str[] = "andy:james:john:amy";
    splitNameCode(str, *output);

    for (int loop = 0; loop<4; loop++) {
        printf("%s\n", output[loop]);
    }

    return 0;
}
  • 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-24T06:05:51+00:00Added an answer on May 24, 2026 at 6:05 am

    Here is a working program for you. Let me know if you need any explanation.

    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    
    void splitNameCode(char *code, char **output) {
        int i = 0;
        char* token = strtok(code, ":");
        while (token != NULL) {
            output[i++] = token;
            token = strtok(NULL, ":");
        }
    }
    
    int main (int argc, const char *argv[]) {
        char* output[4];
        char input[] = "andy:james:john:amy";
        splitNameCode(input, output);
        for (int i = 0; i < 4; i++) {
            printf("%s\n", output[i]);
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am completely a newbie in continuous integration but I am trying to learn
Before anything, I should admit that I am completely a newbie about Java Swing.
I'm trying to build a website that will allow user to upload video files
I'm a complete newbie in OCaml and trying to create a simple console program.
I'm completely newbie at authentication proccess with OAuth (I'm trying to make use of
I'm a Perl newbie. I'm trying to learn based on a previous person's work
I'm a complete newbie to JavaScript trying to understand simple things.... Please look at
Newbie Warning I have a simple but vexing problem trying to disable an NSButton.
I am completely new to Perl, like absolute newbie. I am trying to develop
I'm trying to build an application in my ARM9 (Freindly ARM) board that will

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.