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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:07:28+00:00 2026-06-01T10:07:28+00:00

I’m trying to use pointers and strcat from C. This is part of my

  • 0

I’m trying to use pointers and strcat from C. This is part of my learning process.

The idea is the user inputs a string that contains digits and the output should return only the digits.
So, if the user inputs
te12abc the output should be 12.

This is my first try:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define SIZE 10

int main()
{
    char palavra[SIZE];
    char palavra2[SIZE];
    char *pont = palavra;
    char *pont2 = palavra2;

    printf("Insert the string\n");
    scanf("%s", palavra);

    do{
        if (isdigit(*pont)){
            strcat(palavra2, *pont);
        }
        *pont++;
    }while (*pont != '\0');

    printf("\nThe number is:\n%s\n", palavra2);
    return 0;
}

I believe that the pointer is working as expected but can’t understand why strcat is not working.

Made a second try that is the program finds a number, stores that char in one variable and only then try to use strcat with that variable. Here is the code:

int main()
{
    char palavra[SIZE];
    char palavra2[SIZE];
    char temp;
    char *pont = palavra;
    char * pont2 = &temp;

    printf("Insert the string\n");
    scanf("%s", palavra);

    do{
        if (isdigit(*pont)){
            temp = *pont;
            strcat(palavra2, pont2);
        }
        *pont++;
    }while (*pont != '\0');

    printf("\nThe number is:\n%s\n", palavra2);
    return 0;
}

Once again it gives me problems at strcat.

Made one last attempt but without pointer and still strcat does not work. Here is the code:

int main()
{
    int i = 0;
    char palavra[SIZE];
    char palavra2[SIZE];
    char temp;

    printf("Insert the string\n");
    scanf("%s", palavra);

    do{
        if (isdigit(palavra[i])){
            temp = palavra[i];
            strcat(palavra2, palavra[i]);
        }
        i++;
    }while (palavra[i] != '\0');

    printf("\nThe number is:\n%s\n", palavra2);
    return 0;
}

Can you point me to the right direction? Don’t now what more can I do..

Regards,

favolas

  • 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-01T10:07:29+00:00Added an answer on June 1, 2026 at 10:07 am

    Remove * (dereference),

            strcat(palavra2, pont);
    

    strcat expects a char* not a char
    but this version appends the whole rest.
    you have to create a nul-terminated string.

    And the * is useless

        *pont++;
    

    This does the job

        pont++;
    

    now all at once

    int main()
    {
      char palavra[SIZE];
      char palavra2[SIZE];
      char c2[2] = "a";
      char *pont = palavra;
      char *pont2 = palavra2;
    
      printf("Insert the string\n");
      scanf("%s", palavra);
    
      do{
        if (isdigit(*pont)){
          c2[0] = *pont;
          strcat(palavra2, c2);
        }
        pont++;
    }while (*pont != '\0');
    
    printf("\nThe number is:\n%s\n", palavra2);
    return 0;
    

    However, this is too complicated

    int main()
    {
      char palavra[SIZE];
      char palavra2[SIZE];
    
    
      printf("Insert the string\n");
      scanf("%s", palavra);
    
      char *pont = palavra;
      char *pont2 = palavra2;
    
      while (true) {
        char c = *pont ++;
        if (c == 0) break;
        if (isdigit(c)){
           *pont2++ = c;
        }
      };
      printf("\nThe number is:\n%s\n", palavra2);
      return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.