If we have to allocate memory ...
2 Answers
If we have to allocate memory ...
| Flag | PURGE
If we have to allocate memory to a string of size n and read the string at run time character by character?
And we write the following code then why doesn't it works properly
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,i;
printf("Enter size n: ");
scanf("%d",&n);
char* str=(char*)calloc(n+1,sizeof(char));
for(i=0;i<n;i++)
scanf("%c",&str[i]);
str[n]='\0';
printf("%s",str);
getch();
return 0;
}
i wrote this
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.