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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:41:45+00:00 2026-06-05T17:41:45+00:00

I got 2 arrays : data[256] = 1@2@3@4@5 question[256][256]; I need to split the

  • 0

I got 2 arrays :

data[256] = "1@2@3@4@5"
question[256][256];

I need to split the number before the @ into an array..
for example :

question[0][] = 1
question[1][] = 2
question[2][] = 3
question[3][] = 4
question[4][] = 5

It doesnt metter if I have the @ in, or not.

This is what I wrote :

int i = 0, j = 0;
 data = "1@2@3@4@5";

 for (i = 0 ; i < strlen(data) ; i++)
 {
     for (j ; data[j] != '@' ; j++)
     {
         question[i][j] = data[j];
     }
     j++
 }

 printf ("%s\n", question);

The problem is, it works untill the first @, and then stops.
It only put the first @ into question, and then stops.
(basiclly I’m supposed to get the same output for printing both data, and question).

  • 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-05T17:41:46+00:00Added an answer on June 5, 2026 at 5:41 pm

    There are a few problems.

    First, printf only prints the string until the first terminating zero character ('\0'), which happens after the first “part” in question (even though there are other parts. Instead, you will need to print all:

    for (i=0; i<255; ++i) {
      printf("%s\n", question[i]);
    }
    

    Make sure you null-terminate ('\0') the rows of question before, so you don’t print garbage for uninitialized rows. or just maintain the index of the last-good row and iterate until that

    Also, the loop

    for(j; data[j]!='@', j++)
    

    will stop at the first '@', and all consequent iterations of the outside loop will evaluate the same j (which is the index of '@', so the loop is skipped in further iterations. You will need to advance j after the inner loop

    you will also need to maintain a last-j position after the last '@' to be able to calculate the position of j from the last '@', so you can index into question[i] properly. set lastj to the value of j after is extra advancement suggested in the previous paragraph. Also, the second index of question should be j-lastj from now on.

    Yet another thing about the inner loop: as it is, it will advance past the string in data after the last '@', so you will have to check for noll-termination as well.

    Also, make sure you null-terminate the strings in question, otherwise printf will produce garbage (and possibly seg-fault when reaching memory not allocated to your progam). just write

    question[i][j-lastj] = '\0';
    

    after the inner loop. (j will have pointed after the last written index at the end of the inner loop)

    Yet one more thing: do not iterate i until the length of data as you will not need to touch that many elements (and likely will overindex data in the inner loop). Use a while loop instead, incrementing i only until you have covered data with j in the inner loop

    Note: look up strtok to make the tokenization easier on your part

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

Sidebar

Related Questions

I got an array which contains signed int data, i need to convert each
I have got a problem with my codeigniter library. To transform database data into
I have 4 arrays of different data. For the first array of string, I
I have got a couple of functions that manipulate data in an array, for
using opengl 3.3, radeon 3870HD, c++.. I got question about interleaved arrays of data.
I've got the following example: type Stream (capacity) = let data = Array.zeroCreate capacity
I need some help with union two cell arrays. I have: data{1} = 'alon'
I've got an array with data from a MySQL table in nested set model
I got the following array (shortened ... multiple dot mean that they are data
I've got a data structure that is a hash that contains an array of

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.