Labels

Wednesday, June 9, 2010

total digit of a an int

/*count total digit of an integer :special method */



#include

int main()
{char s[20];
int a;
printf("enter any no :");
scanf("%d",&a);
printf("\nu enter a %d digit no\n",sprintf(s,"%d", a));
return 0;
}

1 comment:

  1. What is the difference between printf and sprintf?

    sprintf: Writes formatted data to a character string in memory instead of stdout

    Syntax of sprintf is:

    #include
    int sprintf (char *string, const char *format
    [,item [,item]...]);

    Here,

    String refers to the pointer to a buffer in memory where the data is to be written.

    Format refers to pointer to a character string defining the format.

    Each item is a variable or expression specifying the data to write.

    The value returned by sprintf is greater than or equal to zero if the operation is successful or in other words the number of characters written, not counting the terminating null character is returned and returns a value less than zero if an error occurred.

    printf: Prints to stdout

    Syntax for printf is:

    printf format [argument]...

    The only difference between sprintf() and printf() is that sprintf() writes data into a character array, while printf() writes data to stdout, the standard output device.

    ReplyDelete