Upcoming SlideShare
×

# C Prog - Strings

775

Published on

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
775
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
54
0
Likes
2
Embeds 0
No embeds

No notes for slide

### C Prog - Strings

1. 1. C Programming - StringsOrganized By: Vinay Arora Assistant Professor, CSED Thapar University, Patiala
2. 2. Program - 1 #include<stdio.h> #include<conio.h> void main() { char a[]="CIVIL DEPARTMENT"; int i=0; clrscr(); for(i=0;i<=15;i++) { printf("%c",a[i]); } getch(); } Vinay Arora CSED
3. 3. Program – 1 (output) Vinay Arora CSED
4. 4. Program - 2 #include<stdio.h> #include<conio.h> void main() { char a[30]="CIVIL DEPARTMENT"; int i=0; clrscr(); while(a[i]!=0) { printf("%c",a[i]); i++; } getch(); } Vinay Arora CSED
5. 5. Program – 2 (output) Vinay Arora CSED
6. 6. Program - 3 #include<stdio.h> #include<conio.h> void main() { char a[]="CIVIL DEPARTMENT"; clrscr(); printf("%s",a); getch(); } Vinay Arora CSED
7. 7. Program – 3 (output) Vinay Arora CSED
8. 8. Program - 4 #include<stdio.h> #include<conio.h> void main() { char a1[]={C,I,V,I,L}; char a2[]={C,I,V,I,L,0}; char a3[6]={C,I,V,I,L}; clrscr(); printf("n%s",a1); printf("n%s",a2); printf("n%s",a3); getch(); } Vinay Arora CSED
9. 9. Program – 4 (output) Vinay Arora CSED
10. 10. Program - 5 #include<stdio.h> #include<conio.h> void main() { char a1[6]={C,I,V,I,L}; clrscr(); printf("n%s",a1); printf("n%.3s",a1); printf("n%-6.2s",a1); printf("n%6.2s",a1); printf("n%10s",a1); printf("n%5s",a1); getch(); } Vinay Arora CSED
11. 11. Program – 5 (output) Vinay Arora CSED
12. 12. Program - 6 #include<stdio.h> #include<conio.h> void main() { char text[20]; int length; clrscr(); printf("Type the Text belown"); gets(text); length=strlen(text); printf("Length of string = %d",length); getch(); } Vinay Arora CSED
13. 13. Program – 6 (output) Vinay Arora CSED
14. 14. Program - 7 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcpy(str1,str2); printf("nn1st String after strcpy() is --->t%s",str1); Vinay Arora CSED
15. 15. Program – 7 (output) Vinay Arora CSED
16. 16. Program - 8 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strncpy(str1,str2,2); printf("nn1st String after strcpy() is --->t%s",str1); Vinay Arora CSED
17. 17. Program – 8 (output) Vinay Arora CSED
18. 18. Program - 9 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int result; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); result=strcmp(str1,str2); //In case of match result will be ZERO otherwise NON ZERO printf("nnResult after Comparing is %d",result); Vinay Arora CSED
19. 19. Program – 9 (output) Vinay Arora CSED
20. 20. Program – 9 (output) Vinay Arora CSED
21. 21. Program - 10 #include<stdio.h> #include<conio.h> void main() { char str1[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("n1st String is --->t%s",str1); strupr(str1); printf("nnString after strupr() is --->t%s",str1); getch(); } Vinay Arora CSED
22. 22. Program – 10 (output) Vinay Arora CSED
23. 23. Program - 11 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20],str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcat(str1,str2); printf("nnString after strcat() is --->t%s",str1); Vinay Arora CSED
24. 24. Program – 11 (output) Vinay Arora CSED
25. 25. Program - 12 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20],str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcat(str1," "); strcat(str1,str2); printf("nnString after strcat() is --->t%s",str1); Vinay Arora CSED
26. 26. Program – 12 (output) Vinay Arora CSED
27. 27. Program - 13 #include<stdio.h> #include<conio.h> void main() { char str1[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("n1st String is --->t%s",str1); strrev(str1); printf("nnString after strrev() is --->t%s",str1); getch(); } Vinay Arora CSED
28. 28. Program – 13 (output) Vinay Arora CSED
29. 29. Program - 14 #include<stdio.h> printf("n1st String is --->t%s",str1); #include<conio.h> void main() strrev(str1); { char c,str1[30]; printf("nnString after strrev() is --->t%s",str1); int length,i=0; clrscr(); getch(); } printf("Enter 1st stringn"); c=getchar(); while(c!=@) { str1[i]=c; i++; c=getchar(); } Vinay Arora CSED
30. 30. Program – 14 (output) Vinay Arora CSED
31. 31. Thnx… Vinay Arora CSED
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.