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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:22:43+00:00 2026-06-14T23:22:43+00:00

void OneDToTwoD(char* rel){ /* all the declarations here */ while(rel[i] != ‘\0’){ i++; }

  • 0
void OneDToTwoD(char* rel){

  /*  all the declarations here */

  while(rel[i] != '\0'){
    i++;
  }

...

In the code above, I am getting all “sometimes” a segmentation fault. and valgrind check throws “Invalid read of size 1” at me at the line
while(rel[i] != '\0'){

In that line, I’m trying to figure out the length of rel.
I know there must be a better way to do this. I can’t just do sizeof can I?

  • 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-14T23:22:44+00:00Added an answer on June 14, 2026 at 11:22 pm

    If i is initialized as zero, and rel is pointed to valid memory block, this will work well.

    1. rel is pointed to invalid memory block or NULL.
    2. rel is not terminated with \0
    3. i is not started with 0.

    And one more answer, you can’t know the size of memory block from pointer. pointer is not memory block. pointer can specify invalid memory block if you want. So if you want to know the length of memory block, add the length argument to the function.

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

Sidebar

Related Questions

- (void) tearDown { // tear-down code here [super tearDown]; } What is the
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
void say(char msg[]) { // using pointer to print out the first char of
void return_input (void) { char array[30]; gets (array); printf(%s\n, array); } After compiling it
void foo() { //some code MyClass m(); //some more code } Does the C++
void max_min(sqlite3 *db) { //call back********* int i, ncols; sqlite3_stmt *stmt; char *sql; const
void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) {
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { xmlParseChunk(context, (const char *)[data bytes], [data length], 0);
void functions::start() { io_iterator_t enumerator; ...some code... result = IOServiceAddMatchingNotification( mNotifyPort, kIOMatchedNotification, IOServiceMatching( IOFireWireLocalNode

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.