Posted by: Sourav | September 25, 2015

Spritnf to place a long in character array,memset for emtying a character array etc in C,Sourav Bhattacharya


#include<stdio.h>
void main()
{
int len=0,i=0;
long  x=548976;
char arr[100]=””;
sprintf(arr,”%ld”,x);
printf(“%s\n”,arr);
while(1)
{
if(arr[i]!=’\0′)
{
len++;
i++;
}
else
break;

}

printf(“the length of the array is %d\n”,len);
memset(&arr[0], 0, sizeof(arr));

len=0;
while(1)
{
if(arr[i]!=’\0′)
{
len++;
i++;
}
else
break;

}
printf(“the length of the array is %d\n”,len);
printf(“the second element is %d\n”,arr[1]);
}

 

 

http://stackoverflow.com/questions/632846/clearing-a-char-array-c

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: