Tuesday, September 29, 2020

, ,

How To Write strcpy Program In C / strcpy function in c

 strcpy function in c programming use to copy a sting from one variable to another variable. This article will help you to teach how to write the strcpy program in c programming.

 

How to Write strcpy Program In C
How to Write strcpy Program In C

strcpy is an library function in c so you have to define <string.h> Library in header of c program and this function return copied value.

Syntax:-

char *strcpy(char *val1, const char *val2);

strcpy program in c programming

#include <stdio.h>
#include <string.h> //string library 

int main() {
   char val1[20] = "strcpy C program";
   char val2[20];

   // copying str1 to str2
   strcpy(val2, val1);

   puts(str2); // Output(strcpy C program)

   return 0;
}


strcpy function can be used with ANSI/ISO 9899-1990 version.

Saturday, September 26, 2020

,

Written C Program for strcmp() and strncmp()

 Learn to usestrcmp() and strncmp()  Library function in c which is defined in <string.h>. 

Here str1 and str2 are two strings for comparison.

The strcmp Function compares str1 to str2 in c program. If str1 is bigger than or adequate to str2, then str1 is a smaller amount than or greater than zero, which returns zero.

The function strncmp in c compares str2 to the n characters of the str1 string. The return value of strncmp is adequate to strcmp.

The positive and negative value given by the strncmp function is that the numerical difference between the primary mismatched characters within the strings.

Str1 and str2 are often character array variables or string constants.

C program for strcmp() and strncmp()


#include <stdio.h>
#include <string.h>

int main()
{
   char str1[ ] = "Computerinhindi"; //initialize character array
   char str2[ ] = "Computerinhindi"; 
   char str3[ ] = "Computerinhindi"; 

   printf("str1 = %s\n"
          "str2 = %s\n"
          "str3 = %s\n\n", str1, str2, str3);

   //comparing given strings
   printf("strcmp(str1, str2) = %d\n", strcmp(str1, str2));
   printf("strcmp(str2, str3) = %d\n", strcmp(str2, str3));
   printf("strcmp(str3, str1) = %d\n\n", strcmp(str3, str1));

   //comparing n characters with help of library function
   printf("strncmp(str1, str3, 3) = %d\n", strncmp(str1, str3, 3));
   printf("strncmp(str1, str3, 6) = %d\n", strncmp(str1, str3, 6));
   printf("strncmp(str3, str1, 6) = %d\n\n", strncmp(str3, str1, 6));

   return 0;
}

OUTPUT For Written C Program for strcmp()

 and strncmp(): - 

C Program for strcmp()  and strncmp(): -
strcmp() and strncmp()


Wednesday, September 23, 2020

,

How to use strlen() function in c


This c program example will help you to find the length of string in c programming with the help of strlen() function in c :-

 

How to use strlen() function in c
How to use strlen() function in c

 

main()
{
    char s1[20];
    int len;
    printf("\nEnter a string to find it's length: ");
    gets(s1);
    len = strlen(s1);
    printf("\ngive the length of string: %d", len);
    getch();
}


Output

Enter a string to find it's length:-functioninc

give the length of string:-11

Thursday, September 10, 2020

C program to seek out the length of the string with or without using strlen function in c


 Here we'll write a C program to seek out the length of the string. The length of the "Computerinhindi" string is 15.

C program to seek out the length of the string with or without using strlen function in c
C program to seek out the length of the string with or without using strlen function in c
Find string length without using string library functions in C programming

To find the length, use for loop or while loop. The program below uses the for loop to check the string length in c program.

#include
int main()
{
     char st[200];
     int i;

     printf("Enter a string: ");
     scanf("%[^\n]",str);

     for(i=0;st[i]!='\0';i++);

     printf("length of given string is=%d",i);

     return 0;
}

The variable i is initialized with 0 inside the for loop. Now the condition str [i]! = '\ 0' are going to be checked for every character within the string. When the condition is true, the worth of the variable i will be able to increment.  


At the top of the string, it encounters a null character ("\ 0") therefore the condition becomes false and therefore the value of the variable i will be able to not increment, loop terminated. Finally, we get the length of the string without employing a built-in strlen () function in C program.

C Program to check String length using strlen()

  •  The strlen () function returns the length of the string passed.
  •  strlen () doesn't count the null character "\ 0"
  •  the specified header file may be a string.
#include
#include
int main()
{
     char a[20]="Computerinhindi";
     char b[20]={'C','O','R','N','N','E','R','\0'};
     char c[20];

     printf("Enter a string: ");
     scanf("%[^\n]",c);

     printf("Length of given string in c program %s =%ld\n",a,strlen(a));
     printf("Length of given string %s =%ld\n",b,strlen(b));
     printf("Length of string in c program %s =%ld\n",c,strlen(c));

     return 0;
 }

Here is that the C program to seek out the length of the string, to require user input we will use gets () or fgets (). The fgets () function also returns the newline character to the string. 

If you employ the fgets () function as shown below, you'll get result = (actual length + 1). The gets () takes an equivalent input length as [^ \ n] took. For an equivalent string, gets () gives the length 14 except for fgets () gives the length 15.

Monday, July 6, 2020

, ,

toLocaleString(),toFixed(), toString() in javascript and more number in javascript

number in javascript: -

There are some function which is used as the javascript number function or method and these functions are used to manipulates the number in javascript for exp: - isInteger(),isNaN(),toLocaleString(), toString() in javascript and many more.

toLocaleString(),toFixed(), toString() in javascript and more number in javascript
toLocaleString(),toFixed(), toString() in javascript and more number in javascript

The Number.isFinite() method determines whether a worth may be a finite number.

This method returns true if the worth is of the sort Number, and equates to a finite number. Otherwise, it returns false.

Number.isFinite() is different from the global isFinite() function. The global isFinite() function converts the tested value to variety , then tests it.

Number.isFinite() doesn't convert the values to Number, and can not return true for any value that's not of the sort Number.

syntax : - 

Number.isFinite(value)
This function returns a boolean value true if the value is a finite Number in javascript or returns false.

Definition and Usage of isInteger() number in javascript : - 

The Number.isInteger() method determines whether a worth an integer.

This method returns true if the worth is of the sort Number, and an integer (a number without decimals). Otherwise, it returns false.

syntax : - 

Number.isInteger(value)

 isNaN() Method of number in javascript: -

The Number.isNaN() method determines whether a worth is NaN (Not-A-Number).

This method returns true if the worth is of the sort Number, and equates to NaN. Otherwise, it returns false.

Number.isNaN() is different from the worldwide isNaN() function. the worldwide isNaN() function converts the tested value to variety , then tests it.

Number.isNaN() doesn't convert the values to variety , and can not return true for any value that's not of the sort Number.

syntax : - 

Number.isNaN(value)

Number isSafeInteger() in javascript:-

The Number.isSafeInteger() method determines whether a worth maybe a safe integer.

This method returns true if the worth is of the sort Number and a secure integer. Otherwise, it returns false.

syntax : - 

Number.isSafeInteger(value)

toExponential() Number in javascript:-

The toExponential() method in javascript converts variety into an exponential notation.

syntax : - 

number.toExponential(x)

toFixed() in javascript:-

 The toFixed() method in javascript converts variety into a string, rounding to a specified number of decimals.

syntax : - 

number.toFixed(x)

Note: if the specified number of decimals is above the particular number, zeros are added to make the specified decimal length.

JavaScript toLocaleString():- 

The toLocaleString() method in javascript converts variety into a string, employing a local language format.

The default language depends on the locale setup on your computer.

syntax : - 

number.toLocaleString(locales, options)

Parameter Values for toLocaleString() in javascript: - 

 ar-SA Arabic (Saudi Arabia)
bn-BD Bangla (Bangladesh)
bn-IN Bangla (India)
cs-CZ Czech (Czech Republic)
da-DK Danish (Denmark)
de-AT Austrian German
de-CH "Swiss" German
de-DE Standard German (as spoken in Germany)
el-GR Modern Greek
en-AU Australian English
en-CA Canadian English
en-GB British English
en-IE Irish English
en-IN Indian English
en-NZ New Zealand English
en-US US English
en-ZA English (South Africa)
es-AR Argentine Spanish
es-CL Chilean Spanish
es-CO Colombian Spanish
es-ES Castilian Spanish (as spoken in Central-Northern Spain)
es-MX Mexican Spanish
es-US American Spanish
fi-FI Finnish (Finland)
fr-BE Belgian French
fr-CA Canadian French
fr-CH "Swiss" French
fr-FR Standard French (especially in France)
he-IL Hebrew (Israel)
hi-IN Hindi (India)
hu-HU Hungarian (Hungary)
id-ID Indonesian (Indonesia)
it-CH "Swiss" Italian
it-IT Standard Italian (as spoken in Italy)
jp-JP Japanese (Japan)
ko-KR Korean (Republic of Korea)
nl-BE Belgian Dutch
nl-NL Standard Dutch (as spoken in The Netherlands)
no-NO Norwegian (Norway)
pl-PL Polish (Poland)
pt-BR Brazilian Portuguese
pt-PT European Portuguese (as written and spoken in Portugal)
ro-RO Romanian (Romania)
ru-RU Russian (Russian Federation)
sk-SK Slovak (Slovakia)
sv-SE Swedish (Sweden)
ta-IN Indian Tamil
ta-LK Sri Lankan Tamil
th-TH Thai (Thailand)
tr-TR Turkish (Turkey)
zh-CN Mainland China, simplified characters
zh-HK Hong Kong, traditional characters
zh-TW Taiwan, traditional characters

JavaScript toPrecision() :- 

The toPrecision() method in javascript formats variety to a specified length.

A percentage point and nulls are added (if needed), to make the required length.

syntax : - 

number.toPrecision(x)

toString() in JavaScript:- 

The toString() function in Javascript is employed with variety and converts the amount to a string. it's wont to return a string representing the required number object.

syntax : - 

number.toString(radix)

Optional. Which base to use for representing a numeric value. Must be an integer between 2 and 36.
  •  2 - the amount will show as a binary value
  •  8 - the amount will show as an octal value
  •  16 - the amount will show as a hexadecimal value

valueof() in JavaScript:- 

The valueof() method in JavaScript is employed to return the primitive value of variety.

This method is typically called internally by JavaScript and not explicitly in web code.

syntax : - 

number.valueOf()

Monday, June 29, 2020

javascript boolean function String to boolean conversion

javascript boolean function String to boolean conversion
javascript boolean function String to boolean conversion

Learn about the javascript boolean function :-

Javascript Boolean can have two values (true and false) like any other programming languages.

Boolean function in javascript return the true value if the condition is true. For example : - 
Boolean(13 > 10)

Boolean toString() Method in javascript : - 

toString() function in boolean javascript gives a boolean value as a string.

Syntax : - 

boolean.toString()

javascript boolean toString() function return the value A String, either "true" or "false".

javascript Boolean valueOf() Method : - 

valueOf() function in boolean javascript gives the primitive value of a boolean.
var bool = false;
var y = bool.valueOf();

Syntax : - 

boolean.valueOf()

javascript boolean valueOf() function return the value A Boolean, either true or false

Saturday, June 20, 2020

javascript date function or date format in javascript and convert js date from string

These all are the most using javascript date formate or method with the help of these function users can find out about the date, time (in hour, minute, millisecond) and year also. The user also can convert the Date into a readable string with the date format in javascript.convert

javascript date function or date format in javascript and convert js date from string
javascript date function or date format in javascript and convert js date from string

Date function in Javascript:-

The date function is used to give information about the date and time.
The date object is started with the new Date().

 Javascript works with the opp's so there are four ways to an initialized Date object.

var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

Now Let's see the Properties of Date Object:-

JavaScript constructor Property:-

constructor property in javascript returns the constructor function for an object and the value of the outcome will be the reference to the function not the name of that function.

Syntax : - 
Date.constructor

JavaScript Date prototype:-

prototype constructor in javascript gives you an opportunity to add new properties and methods to the Date() object.

getDate() function in javascript : - 

getDate function in javascript gives the day of the month of the given date. 

Syntax:-
Date.getDate()

getDay() in javascript : - 

getDay function in javascript gives the day of the week (0 to 6) of the given date. Where 0 is Sunday and 1 is Monday and so on. 

Syntax:-
Date.getDate()

getFullYear() method in javascript : - 

getFullYear() function in javascript gives the year of the given date. 

Syntax:-
Date.getFullYear()

getHours() in javascript : - 

getHours() method in javascript gives the hour of the given date and time. 

Syntax:-
Date.getHours()

getMilliseconds() in javascript : - 

getMilliseconds() method in javascript gives the milliseconds of the given date and time. 

Syntax:-
Date.getMilliseconds()

getMinutes() in javascript : - 

getMinutes() function in javascript gives the minutes of the given date and time.

Syntax:-
Date.getMinutes()

getMonth() in javascript : - 

getMonth() function in javascript gives the month (0-11) of the given date and time based on the local time.
where 0 is January.

Syntax:-
Date.getMonth()

getSeconds() in javascript : - 

getSeconds()gives the output as the seconds of given date and time.

Syntax:-
Date.getSeconds()

getTime() in javascript : - 

getTime() gives the output in milliseconds and it lies between midnight of January 1, 1970  of given date and time.

Syntax:-
Date.getTime()

getTimezoneOffset() in js : - 

getTimezoneOffset()gives the time difference between UTC time and local time, in minutes.

Syntax:-
Date.getTimezoneOffset()

getUTCDate() in javascript : - 

getUTCDate() method in javascript gives day of the month of the given date according to universal time.

Syntax:-
Date.getUTCDate()

getUTCDay() in javascript : - 

getUTCDay() method in javascript gives the day of the week for the gives date according to universal time.

Syntax:-
Date.getUTCDay()

getUTCFullYear() method in javascript : - 

getUTCFullYear() in javascript gives the year of the given date according to universal time (UTC).

Syntax:-
Date.getUTCFullYear()

getUTCHours() in js date function: - 

getUTCHours() gives he hour of the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCHours()

getUTCMilliseconds() in js: - 

getUTCMilliseconds() in javascript gives the milliseconds of the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCMilliseconds()

getUTCMinutes() method in javascript: - 

getUTCMinutes() in javascript gives the  minutes for the given date and time according to universal time (UTC).

Syntax:-
Date.getUTCMinutes()

getMonth() in javascript : - 

getMonth() function in javascript gives the month (0-11) for the given date and time based on the  universal time.

where 0 is January.

Syntax:-
Date.getUTCMonth()

getUTCSeconds() in javascript : - 

getUTCSeconds()gives the output as the seconds(0-59) of given date and time
based on the  universal time.

Syntax:-
Date.getUTCSeconds()

now() date method in javascript : - 

now() function in javascript gives the number of milliseconds since January 1, 1970 00:00:00 UTC.

Syntax:-
Date.now()

parse() date method in javascript : - 

parse() function in javascript use to parses a date string and gives the number of milliseconds since January 1, 1970.

Syntax:-
Date.parse(datestring)

javascript toDateString() method : - 

toDateString() in javascript use to converts the date of a Date object into a readable string.

Syntax:-
Date.toDateString()

toISOString() date method in javascript: - 

toISOString() in javascript use to converts the date of a Date object into a readable string with the help of  ISO standard.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toISOString()

JavaScript toJSON() method: - 

toJSON() in javascript use to converts the date of a Date object into a readable string in JSON format.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toJSON()

toLocaleDateString() date method in javascript: - 

toLocaleDateString() in javascript use to converts the date into a readable string with the help of  locale conventions.

and the iso formate for date:- YYYY-MM-DDTHH:mm:ss.sssZ

Syntax:-
Date.toLocaleTimeString()

JavaScript toLocaleString() method:-

toLocaleString() in javascript use to converts the date into a readable string with the help of locale settings.

Syntax:-
Date.toLocaleString(locales, options)

JavaScript toString() method:-

toLocaleString() in javascript normally use to converts the date into a readable string. 

Syntax:-
Date.toString()

toTimeString() in javascript:-

toTimeString() method use to converts the time portation of date into a readable string.

Syntax:-
Date.toTimeString()

 javascript date UTC method: -

UTC() in javascript gives the number of milliseconds between the given date and midnight of January 1, 1970, according to universal time.

Syntax:-
Date.UTC(year, month, day, hours, minutes, seconds, millisec)

 javascript valueOf() date method: -

valueOf() in javascript gives the primitive value of a Date object.

Syntax:-
Date.valueOf()