CSS PROGRAMMING LANGAUGE disadvantages CSS full form is cascade style sheets , which we call it says about how you should display the HTML elements on the screen. CSS tells us the style of the webpage let us take a simple example, if we build a home first we lay out the design that is known as the HTML language. Where the CSS means layout which means giving instructions on how the furniture should be nothing but the CSS. For example if we take PayPal we can see that the background color blue says the CSS background-color property. Netflix is also the best way of saying CSS property, but if we remove it will be a normal webpage but with the red color and the black plus symbols it looks like the best webpage. Versions of CSS There are differen...
WHAT IS STRING:
![]() |
FUNCTIONS |
- Sequence of characters represented as a single entity is nothing but a string, A character array terminated by a null character(\0) is known as a string.
- For eg:- char name[5]="good"; we can write a string first define the data type that is char, and declare the variable that names, with size 5 equal to double codes good.
- There many ways to create a string, the first one is to define the size [5], the second method is without size, third is to give with predefined size.
C PROGRAM CREATE STRING, DISPLAY IT.
#include<stdio.h>
main()
{
char name[]={"p", "o", "s", "i", "t", "i", "v", "e"};
int i=0;
while(name[i]='\0')
{
printf("%c",name[i]);
i++;
}
}
- Firstly declare the stdio. h, then the main function declares the char data type, and name variable within the curly brackets write the words and by using the while loop check it if executes do incrementation.
PROGRAM PROMPT USER NAME, DISPLAY IT
#include<stdio.h>
main()\
{
char name[42];
printf("enter your name:");
scanf("%s",name);
printf("your name is %s",name);
}
- Gets() function is used to store the given string in place of scanf, we use it in strings.
- If we use user input containing a space in the text, this program takes the next up to the space only in order to remove we use this function.
Program gets() function
#include<stdio.h>
main()
{
char name[42];
printf("enter your name:");
gets(name);
printf("name is %s",name);
}
- puts() library function is used to display the text we use printf in c programs but in strings.
- The main thing in this is the gets function which stores the name value and prints it on the monitor.
PUTS() FUNCTION
#include<stdio.h>
main()
{
char name[6];
strcpy(name,"hi");
puts(name);
}
- Puts functions place the name value and consoles it on the monitor.
String manipulation functions
- In the header file "string.h", following library functions are provided to deal with strings.
- There are strcat() this library function appends or adds at the end one string to the other.
Syntax:- strcat(s1,s2);
#include<stdio.h>
void main()
{
char s1[]="Hello";
char s2[]="hi";
strcat(s1,s2);
printf("%s",s1);
}
Output:- "Hello hi"
- strcpy() library function almost acts as a string assignment operator, It assigns a string literal to a string-type variable, Copies the content of the string to the other.
#include<stdio.h>
#include<string.h>
main()
{
char s1[10]="";
char s2[10]="hello";
strcpy(s1,s2);
printf("%s",s1);
}
- This function copies the value double codes and then hello prints it.
Output on the console: "Hello"
- strlen(): This is used to find the length of the string i.e. to find the number of characters in the string.
#include<stdio.h>
#include<string.h>
main()
{
char college[]="iii";
int n=strlen(college);
printf("length of the string is %d",n);
}
- It finds the length of the string we can either give the length or define it while writing the code.
- strcmp(): Compare two strings for equality if they are equal, this function returns 0.
#include<string.h>
main()
{
char s1[]="hello";
char s2[]="hi";
int n=strcmp(s1,s2);
if(n==0)
printf("the given strings are equal");
else
printf("not equal');
}
- strncpy(): Copies specified number of content from one string to the other.
#include<stdio.h>
#include<string.h>
void main()
{
char str1[30]="hi";
char str2[40]="hello";
strncpy(str1);
strncpy(str2);
printf("%d\n");
}
- strncat(): Adds the specified content from string to other.
#include<stdio.h>
#include<string.h>
void main()
{
char str1[10]="world";
char str2[20]="hello";
strncat(str2,str1);
}
- strncmp(): Compares the required number of characters from strings.
#include<stdio.h>
#include<string.h>
void main()
{
char s1[30];
char s2[10];
if(s1=s2)
{
printf("successfully");
}
else
{
printf("not");
}
- strstr(): Search for a string in another string.\
#include<stdio.h>
#include<string.h>
void main()
{
char ch[50]="whats";
char s4[40]="up";
if(ch==s4)
{
printf("executed");
}
else
{
printf("not");
}
- In the previous blogs we learned about different operators and their types of arithmetic, and assignments.
Comments
Post a Comment