My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.

Monday, 15 August 2011

Print Character Using malloc

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

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls