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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:29:24+00:00 2026-05-16T01:29:24+00:00

Im trying to remove the first char of the string and keep the remainder,

  • 0

Im trying to remove the first char of the string and keep the remainder, my current code doesnt compile and im confused on how to fix it.

My code:

char * newStr (char * charBuffer)
{
    int len = strlen(charBuffer);
    int i = 1;
    char v;
    if(charBuffer[0] == 'A' || charBuffer[0] == 'Q'){
        for(i=1;i<len;i++)
            v = v + charBuffer[i];
    }
    v = v + '\0';
    return v;
}

Gcc: “Warning: return makes pointer from integer without a cast”

Also: “char * newStr (char * charBuffer)” needs to remain the same.

  • 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-16T01:29:25+00:00Added an answer on May 16, 2026 at 1:29 am

    Strings don’t work like this in C. You’re summing up all of the characters in the buffer into the v variable. You can’t use + to concatenate. The code you posted has some serious problems which indicate that there’s an understanding gap with how to use C.

    Try this:

    char *newStr (char *charBuffer) {
      int length = strlen(charBuffer);
      char *str;
      if (length <= 1) {
        str = (char *) malloc(1);
        str[0] = '\0';
      } else {
        str = (char *) malloc(length);
        strcpy(str, &charBuffer[1]);
      }
      return str;
    }
    

    or this:

    char *newStr (char *charBuffer) {
      char *str;
      if (strlen(charBuffer) == 0)
        str = charBuffer;
      else
        str = charBuffer + 1;
      return str;
    }
    

    Depending on whether you want to allocate a new string or not. You’ll also have to add the code for handling the cases that don’t start with ‘Q’ or ‘A’. I didn’t include those because I’m not sure exactly what you’re trying to do here.

    Make sure you do some research into allocating and deallocating memory with malloc and free. These are fundamental functions to be able to use if you’re going to be doing C programming.

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

Sidebar

Related Questions

I'm trying to remove the first 13 characters of a string with this code:
I'm trying to write some code to remove the first N characters in a
I'm trying to remove all but the first child component from a Java Container.
I'm trying to use Unix cut to remove the first two fields per line.
I'm trying to remove an item from an array based on string; public function
I'm trying to remove all users from an AD group with the following code:
Strange situation: I am trying to remove some hard coding from my code. There
I am trying to remove the first wrapping tag of an image IF one
I am trying to remove the object at index 1 but the code won't
I'm trying to remove the first two columns (of which I'm not interested in)

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.