Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEPARTMENT OF COMPUTER SCIENCE & APPLICATION

Similar presentations


Presentation on theme: "DEPARTMENT OF COMPUTER SCIENCE & APPLICATION"— Presentation transcript:

1 DEPARTMENT OF COMPUTER SCIENCE & APPLICATION
BILASPUR UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE & APPLICATION TOPIC :- STRINGS GUIDED BY: PRESENTED BY:- Mr.Jitendra kumar Ritu singh

2 Strings A special kind of array is an array of characters ending in the null character \0 called string arrays A string is declared as an array of characters char s[10] char p[30] When declaring a string don’t forget to leave a space for the null character which is also known as the string terminator character

3 Standard library string function
strcpy - copy one string into another. strcat - append one string onto the right side of the other. strrev – reverses string.

4 strcpy strcpy(destinationstring, sourcestring)
Copies sourcestring into destinationstring For example strcpy(str, “hello world”); assigns “hello world” to the string str

5 strcpy example #include <stdio.h> #include <string.h>
Int main() { Char source[ ] = “RITU”; Char target [10]; Strcpy( target , source); Printf(“source string = %s\n”,source); Printf(“target string = %s\n”,target); Return 0; }

6 Usre difine function #include<stdio.h> #include<conio.h>
Char mystrcpy( char *t, char *s) { While(*s != ‘\0’) *t = *s; s++; t++; } Return *t ; Void main() Char source [ ] = “ ram “ ; Char target [ 6 ] ; mystrcpy( target , source ); Printf(“\n source string = %s ,\n target string = %s “, source,target); Out put :-= source string = ram target string = ram

7 strcat strcat(destinationstring, sourcestring)
appends sourcestring to right hand side of destinationstring For example if str had value “a big ” strcat(str, “hello world”); appends “hello world” to the string “a big ” to get “ a big hello world”

8 Library function #include <stdio.h> #include <string.h>
void main() { Char source [ ] = “ RITU”; Char target [10] = “SINGH”; Strcat ( target,source); Printf (“ source string = %s\n”,source); printf(“target string = %s\n”,target); } Out put :- source string =RITU target string = SINGHRITU

9 #include<stdio.h>
#include<conio.h> char mystrcat( char *t, char *s) { While( *t != ‘\0’) t++; } While(*s!=‘\0’) *t = * s ; s++; target =‘\0’; return target ; void main() str1[ ] = “ hello”; Str2 [ 10] =“simple”; mystrcat(str1,str2); Printf(“ %s %s “, str1,str2);

10 THANK YOU


Download ppt "DEPARTMENT OF COMPUTER SCIENCE & APPLICATION"

Similar presentations


Ads by Google