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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:15:43+00:00 2026-06-13T19:15:43+00:00

I have already implemented some of the recommendations before in Code Review . I

  • 0

I have already implemented some of the recommendations before in Code Review. I also improved my code by using pointers. However, what is wrong with address incrementation part below squeezed_str++? It seems that address is not incrementing. Please advise.

PS. substring() function is working. 🙂

char *squeeze (char *str, int start_index, int end_index, char *ref_str) {
     char *substr;
     substr = malloc (sizeof (*substr));
     if (substr == NULL) {
          printf ("Unable to allocate memory.\n");
          exit (EXIT_FAILURE);
     }

     char *squeezed_str;
     squeezed_str = malloc (sizeof (*squeezed_str));
     if (squeezed_str == NULL) {
          printf ("Unable to allocate memory!\n");
          exit (EXIT_FAILURE);
     }

     substr = substring (str, start_index, end_index);
     int substr_len = strlen (substr);
     int refstr_len = strlen (ref_str);

     char chr1, chr2; chr1 = chr2 = '\0';

     for (int i = 0; i < substr_len; i++) {
          chr1 = *(substr+i);
          for (int j = 0; j < refstr_len; j++) {
               chr2 = *(ref_str + j);
               if (chr1 == chr2) {
                    break;
               }
          }
          if (chr1 != chr2) {
               *squeezed_str = *(substr+i);
               squeezed_str++;
          }     
     }

     return squeezed_str;
 } /* end of squeeze() */
  • 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-13T19:15:44+00:00Added an answer on June 13, 2026 at 7:15 pm

    Some improvements with inline advice, not tested:

    char *squeeze (char *str, int start_index, int end_index, char *ref_str) {
         char *substr = substring (str, start_index, end_index);
             //do not malloc here!, you are doing an assignment later on, so memory leak
             //infact might as well move assignment right here
    
         char *squeezed_str;
         squeezed_str = malloc (strlen(str)+1); //+ 1 one for null terminator
         if (squeezed_str == NULL) {
              printf ("Unable to allocate memory!\n");
              exit (EXIT_FAILURE);
         }
    
         int substr_len = strlen (substr);
         int refstr_len = strlen (ref_str);
         int squeezeStrIdx = 0;
    
         for (int i = 0; i < substr_len; i++) {
              char chr1 = substr[i]; //using index accessing is nicer
                                     //moved the scope of the variable in
              char chr2 = '\0'; //reduced variable scope, benefit is now resets each loop
              for (int j = 0; j < refstr_len; j++) {
                   chr2 = ref_str[j];
                   if (chr1 == chr2) {
                        break;
                   }
              }
              if (chr1 != chr2) {
                   squeezed_str[squeezeStrIdx] = chr1;
                   squeezeStrIdx++; //if you modify squeezed_str,
                                    //how do you expect to return it at end of method?
              }     
         }
    
         //this is to null terminate the squeezed_str
         squeezed_str[squeezeStrIdx] = '\0';
    
         return squeezed_str;
     } /* end of squeeze() */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already implemented some AJAX pagination in my Rails app by using the
I've have already implemented pagination using the following code: public Paginacao<Anuncio> consultarPaginado(int pagina, Integer
Before I start: I'm programming for Iphone, using objective C. I have already implemented
i am using the code i have already implemented the table drag and drop
I have already implemented a functionallity, when keeper automatically moves using breadth first search
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried
I have One Project Which is Already Implemented in IPhone(more than 2 yeas ago).
How can I write unit tests for existing and already implemented code which has
In my previous projects, I have already implemented undo system in c++, and I
I need to implement compiler (lexical, syntax and semantic analyzers). I have already implemented

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.