Question

In C Create memory space for text string at run time using malloc() function, text string...

In C

Create memory space for text string at run time using malloc() function, text string will be inputted by the user and displayed. Use free() function that release the occupied memory.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>

int main() {
    char *str = (char *)malloc(sizeof(char) * 100);
    printf("Enter a string: ");
    scanf("%s", str);
    printf("You entered: %s\n", str);
    free(str);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
In C Create memory space for text string at run time using malloc() function, text string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Malloc function For the prelab assignment and the lab next week use malloc function to allocate...

    Malloc function For the prelab assignment and the lab next week use malloc function to allocate space (to store the string) instead of creating fixed size character array. malloc function allows user to allocate memory (instead of compiler doing it by default) and this gives more control to the user and efficient allocation of the memory space. Example int *ptr ptr=malloc(sizeof(int)*10); In the example above integer pointer ptr is allocated a space of 10 blocks this is same as creating...

  • in mip assembly language Memory/Heap Management Software: Write a ‘malloc’ service that takes a piece of...

    in mip assembly language Memory/Heap Management Software: Write a ‘malloc’ service that takes a piece of memory (that you preallocate using the .space directive) and offers a malloc function that allows a user to specify the number of bytes of memory he/she wishes to allocate and returns the memory address of a block of memory that is at least that number of bytes large. You service should also have functions to free memory and keep track of which memory is...

  • **C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation?...

    **C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation? 1. Making the free function do nothing 2. Increasing the alignment requirement for objects 3. Changing from an implicit to an explicit free list 4. Adding footer boundary tags in addition to headers 5. Using a best-fit instead of a first-fit search Q: It is possible to use garbage collection with C programs, but with this limitation: 1. The size of an object cannot...

  • Without using isdigit, create a C function that scans in a string, checks if its an...

    Without using isdigit, create a C function that scans in a string, checks if its an int, and returns the int. If the string is an integer, the function should return the int otherwise return “not a number.” i.e. if user enters “5", the function returns 5, but if the user enters “hi” the function will return “not a number."

  • In C# You will be prompting the user for a text string a list of bills...

    In C# You will be prompting the user for a text string a list of bills they have every month. a. This should be a comma separated list , bill1, bill2, bill3 b. Validate that this text string is not left blank. 3. Create a custom function called CreateBillArray a. This function should accept the string variable that holds the bills. b. Inside of the function, split the text string of the bills into a string array with each individual...

  • Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as t...

    Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as the input a provided string for the sample name (sname) and number for strength (strgth) - open a text file named mytensiledata.txt, with permission to read or append the file. - Make sure to capture any error in opening the file - Write sname and strgth to the file - Close the file...

  • Create a C++ function that reads a line of text from a file (of any name),...

    Create a C++ function that reads a line of text from a file (of any name), saves the line, and prints it out using cout. Use the string stream class <sstreams>

  • In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE...

    In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all requests of allocation of memory space by different users (one thread per user) …. HINT(You will use Pthreads and Semaphores). Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management...

  • (1) Prompt the user to enter a string of their choosing. Store the text in a...

    (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

  • *Using C++* You will create a program that uses a Critter class to move around a...

    *Using C++* You will create a program that uses a Critter class to move around a Grid, which is also a class. The Critter and the Grid classes will be in separate files. The Critter class will have a data member to count the number of moves made. It will also need data members to hold the current x and y coordinates. It will have a member function that randomly moves it one space in one of 4 directions. You...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT