Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

C language £0.50

Title: Strings
Description: Basic to advance coverage of Strings concept in DSA and practice questions.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


22
...
Character arrays are called
strings
...

Initialization of string can be done by following ways
...
Compiler
inserts the null character automatically
...
C program for printing any string
...
h>
void main()
{
char name[]= “India”;
int i=0;
while(name[i]!=‟\0‟)
{
printf(“%c”, name[i]);
i++;
}
}
Output: India
22
...

#include ...
It does not consider space in string
...
For solving this problem, we use „gets‟
function in place of „scanf()‟
...


#include ...
2 Some standard library string function:
Function
strlen
strlwr
strupr
strcat
strcpy
strcmp
strrev

Use
Finds length of a string
...

Converts a string to uppercase
...

Copies a string into another
...

Reverses string
...
3 C program for calculating the length of any string using library function (strlen)
...
h>
#include ...
4 C program for calculating the length of any string without using library function
...
h>
#include ...
h>
int String_Length(char *);
void main()
{
char s[]="shashank";
int len;
clrscr();
len=String_Length(s);
printf("\n The length of string is %d", len);
getch();
}
int String_Length(char *p)
{
int l=0;
while(*p!='\0')
{
l++;
p++;
}
return(l);
}
Output:
The length of string is 8
22
...

#include ...
h>
void main()
{
char s1[]= “Shashank”;
char s2[10];
strcpy(s2, s1);
printf(“\n First string is %s”, s1);
printf(“\n Second string is %s”, s2);
}
Output:
First string is Shashank

Second string is Shashank
22
...

#include ...
h>
#include ...
7 C program for concatenating two strings using library function (strcat)
...
h>
#include ...
8 C program for concatenating two strings without using library function
...
h>
#include ...
h>
void Concat_String(char *,char*);
void main()
{
char s1[20]="shashank";
char s2[]=" yadav";
clrscr();
Concat_String(s1,s2);
printf("\n The concat string is %s",s1);
getch();
}
void Concat_String(char *p1,char *p2)
{
while(*p1!='\0')
{
p1++;
}
while(*p2!='\0')
{
*p1=*p2;
p1++;
p2++;
}
*p1='\0';
}
Output:
The concat string is shashank yadav
22
...

#include ...
10 C program for comparing two strings without using library function
...
h>
#include ...
h>
int Compare_String(char *,char *);
void main()
{
char s1[]="Shyam";
char s2[]="Ram";
int i, j, k;
clrscr();
i=Compare_String(s1,"Shyam");
j=Compare_String(s1,s2);
k=Compare_String(s1,"ShyamSundar");
printf("\n%d %d %d",i,j,k);
getch();
}
int Compare_String(char *p1,char *p2)
{
int c;
while(*p1!='\0'||*p2!='\0')
{
if(*p1!=*p2)
{
return(*p1-*p2);
}
else
{
p1++;
p2++;
}
}
if(*p1=='\0'&&*p2=='\0')

return(0);
}

22
...

#include ...
h>
#include ...
12 Another C program for checking given string is Palindrome or not
...
h>
#include ...
h>
void main()
{
char s[10], t[10];
clrscr();
printf("Enter one string: ");
gets(s);
strcpy(t, s);
strrev(s);
if(strcmp(s,t)==0)
printf("Palindrome");
else
printf("Not Plalindrome");
getch();
}


Title: Strings
Description: Basic to advance coverage of Strings concept in DSA and practice questions.