Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<ctype.h>
- #include<string>
- void nhapchuoi(char s[])
- {
- printf("\nnhap chuoi:");
- gets(s);
- }
- void xuatchuoi(char s[])
- {
- printf("\nxuat chuoi:");
- puts(s);
- }
- void demkt(char s[])
- {
- int dem = 0;
- for (int i = 0; i < strlen(s); i++)
- {
- if (s[i] == ' ')
- dem++;
- }
- if (dem != 0)
- printf("\nchuoi co %d khoang trang", dem);
- else
- printf("chuoi khong co khoang trang");
- }
- void xoathua(char s[])
- {
- while (strstr(s, " "))
- {
- if (s[0] == ' ')
- s[0] = s[1];
- else
- {
- for (int i = 0; i < strlen(s); i++)
- {
- if (s[i] == ' '&&s[i + 1] == ' ')
- {
- for (int j = i + 1; j < strlen(s) - 1; j++)
- s[j] = s[j + 1];
- s[strlen(s) - 1] = '\0';
- }
- }
- }
- }
- xuatchuoi(s);
- }
- void main()
- {
- char s[100];
- nhapchuoi(s);
- xuatchuoi(s);
- demkt(s);
- xoathua(s);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement