Program in C to Accept a String from User and Print it Character by Character Using "malloc"
#include<stdio.h>#include<conio.h>
void main()
{
int le=0,i=0;
char *pc="";
clrscr();
printf("Enter total number of characters\n");
scanf("%d",&le);
pc=(char*)malloc(le*sizeof(char));
printf("\nEnter a string of %d characters\n",le);
scanf("%s",pc);
printf("\nPrinting String Character by Character\n");
for(i=0;i<=le-1;i++)
{
printf("%c\n",*(pc+i));
}
getch();
}
No comments:
Post a Comment