Download
string n.
Skip this Video
Loading SlideShow in 5 Seconds..
String PowerPoint Presentation

String

144 Vues Download Presentation
Télécharger la présentation

String

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. String

  2. #include<stdio.h> #include<conio.h> void main( ) { char *ch1 = "Hello, I am being shown using Pointer"; char ch2[ ]= "Hello, I am being shown using Array" ; printf("\n%s \n\n%s", ch1, ch2); }

  3. #include<stdio.h> #include<conio.h> void main( ) { int n; char *city[5]={"Dhaka", "Sylhet", "Rajshahi", "Khulna", "Chittagong"}; for (n=0 ; n<5 ; n++) printf("\nCity name[%d] is %s", n, city[n]); }

  4. puts( ) #include<stdio.h> #include<conio.h> void main( ) { char *ch1 = "Hello, I am being shown using Pointer"; char ch2[ ]= "Hello, I am being shown using Array" ; puts(ch1); puts(ch2); }

  5. scanf( ) #include<stdio.h> #include<conio.h> void main ( ) { char name[30]; int age; printf("\n What is your name??:"); scanf("%s", name); printf("\nNow what is your age??:"); scanf("%d", &age); if (age<=0) printf("\nSorry %s, Age cannot be negetive", name); if (age>0 && age<=20) printf("\nOh %s, You are just a kid",name); else printf("\nHmm %s,You seem to be old", name); }

  6. gets( ) #include<stdio.h> #include<conio.h> void main ( ) { char name[30]; int age; printf("\n What is your name??:"); gets(name); printf("\nNow what is your age??:"); scanf("%d", &age); if (age<=0) printf("\nSorry %s, Age cannot be negetive", name); if (age>0 && age<=20) printf("\nOh %s, You are just a kid",name); else printf("\nHmm %s,You seem to be old", name); }

  7. Working with strings

  8. #include<stdio.h> #include<conio.h> #include<string.h> void main ( ) { char name1[30], name2[40] ; int x ; printf("\nEnter the first string:") ; gets(name1); printf("Enter the second string:") ; gets(name2); x= strcmp (name1, name2); if(x!=0) printf("\n\nTwo strings that you have entered are not equal"); else printf("\n\nTwo strings are equal"); }

  9. #include<stdio.h> #include<conio.h> #include<string.h void main ( ) { char name1[30], name2[40]; int x,y ; printf("\nEnter the first string in lower case:"); gets(name1); printf("\nEnter the second string in Upper Case:"); gets(name2); strupr(name1); strlwr(name2); printf("\nHere is your first string converted into upper case:") ; puts(name1); printf("\nHere is your second string converted into lower case:") ; puts(name2); }