write a c program to allocate dynamic memory for one string scan it print it
"Write a C program to allocate dynamic memory for one string, scan it, and print it" means to write a program in the C programming language that performs the following tasks:
-
Dynamically allocate memory for a string: This means that the program should request memory space from the operating system at runtime to store a string.
-
Scan the string: This means that the program should prompt the user to input a string and store it in the memory space allocated in step 1.
-
Print the string: This means that the program should retrieve the string stored in the memory space allocated in step 1 and print it to the console.
Overall, this program should demonstrate how to allocate dynamic memory in C, how to scan user input for a string, and how to print the string to the console.
C program to allocate dynamic memory for one string scan & print it
#include<stdio.h>
#include<stdlib.h>
void main()
{
char *p;
p=malloc(sizeof(char)*10);
printf("eneter the string:\n");
scanf("%s",p);
printf("p=%s\n",p);
}
Output: eneter the string: Balmiki
p=Balmiki