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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:19+00:00 2026-05-26T09:33:19+00:00

I have a few questions regarding array of strings in C. I have an

  • 0

I have a few questions regarding array of strings in C.

I have an array char *string. I have a char *string and then I split every 4 characters in a array of strings called sep_str. So for example if char *string = 'The sum';, then char **sep_str is:

0: |_| --> "The "
1: |_| --> "Sum"

My first question is, in an array of strings in C (so array of array of chars), will there be a null terminating character at the end of each sep_str[i], or just at the last position of sep_str? Here is how I copy string into an array of strings:

    for (int i = 0; i < str_length; i++) {
        sep_str[i/4][i%4] = *ptr;
        ptr++;
    }

My second question is, how would I reverse the elements of each string in sep_str? Here’s how I did it, but I feel like it is stepping out of the array of the substring. (so out of the element of the sep_str):

// Reverse each element in the array
    char temp;

    for (int i = 0; i < num_strs; i++) {

        for (int j = 0, k = 4; j < k; j++, k--) {

            temp = sep_str[i][j];
            sep_str[i][j] = sep_str[i][k];
            sep_str[i][k] = temp;
        }
    }
  • 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-26T09:33:20+00:00Added an answer on May 26, 2026 at 9:33 am

    The copy of the strings sounds good to me. Since each string has always 4 chars, you can avoid the null terminator \0. Alternatively you need to declare sep_str as a 5x(lenght/4) matrix, to store the \0 char at the end of each string.

    To reverse a string you need to iterate from the start to the middle of the string, replacing the i-th char with the length-i-1-th. You need to replace the inner for replacing k=3 to k=2.

    You also need to take care of the last string, since the lenght might not be multiple of four.

    char temp;
    
    for (int i = 0; i < (num_strs - 1); i++) {
        for (int j = 0, k = 3; j < k; j++, k--) {
            temp = sep_str[i][j];
            sep_str[i][j] = sep_str[i][k];
            sep_str[i][k] = temp;
        }
    }
    
    if (num_strs > 0) {
        for (int j = 0, k = strlen(sep_str[i]) - 1; j < k; j++, k--) {
            temp = sep_str[i][j];
            sep_str[i][j] = sep_str[i][k];
            sep_str[i][k] = temp;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie user of Frama-C and have a few questions regarding assertions
I'm very new to TDD world. I have a few questions regarding TDD. Do
I have a few basic questions regarding the syntax and usage of properties in
I have a few questions regarding JavaScript obfuscation on client side. First question :
I have a few questions regarding differentiation between const and non-const versions of methods
I am a beginner to networking and I have a few questions regarding networking.
I know there are few questions regarding this issue of 'getView called few times'
I have few questions regarding HornetQ: What are differences between HornetQ core API and
i have a few questions regarding libevent2 and its multithread support. Does libevent support
I have a few questions regarding the Windows Azure Table Storage. Unfortunately my trial

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.