- #1
AK2
- 39
- 0
I am doing a question (its not home work just an exercise). The following is the question.
This is my code.
I run it using Dev C++ development ide which uses the GNU C compiler.
The code compiled. It didnt run and it gave an error message. This is frustrating. If possible can someone explain gets() function and malloc function because I'm not really understanding it from the book I'm using. I understand the basics like what strings are, characters, ASCII code and the like.
Code:
Write code that allocates space for an 80-character string and then inputs a string from the keyboard and stores it in the allocated space.
This is my code.
Code:
#include <stdio.h>
#include <stdlib.h>
char *ptr, *p;
main()
{
ptr = malloc(81);
p = ptr;
printf("Enter some text");
gets("p");
printf("You entered : %s", *ptr);
return 0;
}
The code compiled. It didnt run and it gave an error message. This is frustrating. If possible can someone explain gets() function and malloc function because I'm not really understanding it from the book I'm using. I understand the basics like what strings are, characters, ASCII code and the like.