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

  • Home
  • SEARCH
  • 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 8788815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:13:54+00:00 2026-06-13T22:13:54+00:00

I’m trying to modify a previous program I wrote using pure pointer notation. It’s

  • 0

I’m trying to modify a previous program I wrote using pure pointer notation. It’s a program that generates a random string of 40 uppercase letter, takes input of up to 20 uppercase letter, and input of a character. The program replaces reoccurring characters in the generated string with the character entered. Right now, I’m trying to pass the parameters of the randomly generated string so I can access them in the second function and can’t figure out how to do it.

Thank you for the help.

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

/* Function prototypes */
void fillS1(char * x);

void fillS2(char * x, char * y, char z);

void strFilter(char * a, char * b, char c);

int main(int argc, const char * argv[])
{

char s1[41];
char s2[21];
char x = 0;

char * pointerToS1;
char * pointerToS2;

pointerToS1 = s1;
pointerToS2 = s2;

fillS2(pointerToS2, pointerToS1, x);

return 0;
}

/* Function to generate a random string of 40 uppercase letters */
void fillS1(char * randomlyGeneratedPointer)
{
char randomlyGeneratedArray[41];

randomlyGeneratedPointer = randomlyGeneratedArray;

int i;

for (i = 0; i < 40; i++) {
    *(randomlyGeneratedPointer + i) = 'A' + rand() % 26;
}


}

/* Function to get user input of characters */
void fillS2(char * userStringPointer, char * randomStringPointer, char     replacementCharacter)
{

char userstring[21];
char randomString[41];
char copyString[42];
//char * pointerToCopyString = copyString;

userStringPointer = userstring;



int i = 0;
int n = 0;
int lowercaseCheck = 0;

char loopContinue = 0;




fillS1(randomStringPointer);  //here is the function call for the randomly generated       string.



printf("This is the random string: %s", randomStringPointer);

do {

    /* For loop to copy the first randomly generated string */
    for(i = 0; i < 42; i++)
        *(randomStringPointer + i) = copyString[i];

    randomStringPointer = copyString;

    i = 0;
    lowercaseCheck = 0;

    /* While loop to to get user input */
    printf("Please enter at least 2 capital letters and a maximum of 20.\n");
    while  ((((*(userStringPointer + i)) = getchar()) != '\n'))  {

        /* Counter to determine how many characters were entered */
        i++;

    }

    /* Adding 1 to add to add null character */
    i++;

    *(userStringPointer + i) = '\0';

    //printf("This is the user's string %s", userStringPointer);

    /* Capital letter check */
    for (n = 0; n < 20; n++) {
        if (((*(userStringPointer + n)) >= 'a') && (*(userStringPointer + n) <= 'z')) {

            lowercaseCheck++;
        }
    }

    if (--i < 3) {
        printf("You need at least two letters\n");
    }

    else if (i > 21){
        printf("You cannot have more than twenty letters\n");
    }

    else if (lowercaseCheck == 0) {

        puts(userStringPointer);

        printf("Enter a character to replace occuring letters.\n");
        scanf("%c", &replacementCharacter);
        getchar();

        //printf("this is the copy string before strFilter: %s", randomStringPointer);
        //printf("This is the replacement character %c", replacementCharacter);

        strFilter(randomStringPointer, userStringPointer, replacementCharacter);

    }

    else

        printf("You  must have 2 capital letters.\n");


    printf("Would you like to enter another string (y/n)?\n");
    loopContinue = getchar();
    getchar();


} while (loopContinue != 'n' && loopContinue != 'N');

}

/* Function to replace letters with the character chosen by the user */
void strFilter(char * replacementCopyStringPointer, char * replacementUserStringPointer,         char c)
{

int i = 0;
int n = 0;

while (n < 20) {

    for (i = 0; i < 40; i++) {
        if ((*(replacementCopyStringPointer + i)) == *(replacementUserStringPointer + n)){
            *(replacementCopyStringPointer + i) = c;
        }
    }
    i = 0;
    n++;
}

puts(replacementCopyStringPointer);
}
  • 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-13T22:13:55+00:00Added an answer on June 13, 2026 at 10:13 pm

    randomlyGeneratedArray array in fillS1 would get destroyed once fillS1 function returns.
    You should allocate the memory from heap for randomlyGeneratedArray.

    randomlyGeneratedArray = (char *)malloc(sizeof(char)*41)

    Also do the same for userStringPointer in fillS2.
    That should solve the problem.

    For difference between stack and heap read this question What and where are the stack and heap?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.