Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to transform strings tho holes

+8 votes
asked Apr 29 by Jerónimo Rosas Rondón (260 points)

2 Answers

+2 votes
answered Apr 30 by Peter Minarik (88,520 points)
edited Apr 30 by Peter Minarik

What is a hole? Do you mean (whole) an integral number? What language are we talking about?

In C, you can use atoi().

int i = atoi("123");
printf("i =  %d\n", i);

In Python you can convert string to integer via the constructor of an int:

string = "123"
number = int(string)

In C# various conversion options exist, such as int.TryParse() or Convert.ToInt32().

Java has also various methods. Check this out: https://sentry.io/answers/how-do-i-convert-a-string-to-an-int-in-java/

commented May 1 by Brokers (100 points)
You can use std: :stoi (string to integer) to find that too. This one's better because it throws you an invalid_argument if an error occurs, which you can catch and output an error message.
(#include <string>)
0 votes
answered May 10 by aditi tiwari (180 points)
#include <stdio.h>
#include <string.h>

void transformString(char str[], char hole) {
    for (int i = 0; str[i] != '\0'; i++) {
        if (str[i] != ' ') { // Replace characters that are not spaces
            str[i] = hole;   // Replace with the specified "hole" character
        }
    }
}

int main() {
    char str[100];
    char hole;

    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);

    printf("Enter the character to represent holes: ");
    scanf(" %c", &hole); // Note the space before %c to consume any preceding whitespace

    transformString(str, hole);

    printf("Transformed string: %s\n", str);

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...