Lập trình C- Bài tập 8 potx

2 307 0
Lập trình C- Bài tập 8 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

#include<iostream.h> #include<stdio.h> #include<string.h> //Xóa kho ng tr ng b ên trái xâu void rtrim(char *s) { int i=strlen(s) - 1; while(s[i]==' '&&i>0) i ; s[i+1]=0; } //Xóa các kho ng tr ng d u xâu void ltrim(char *s) { int i=0; while(s[i]==' ') i++; int length=strlen(s); //strncpy(t,s+i,strlen(s) - i); for(int k=0;k<=length;k++) s[k]=s[k+i]; } //Xóa các kho ng tr ng th a trong xâu void ctrim(char *s) { int i=0; while(i<strlen(s) - 1) { if(s[i]==' ' && s[i+1]==' '){ int k=i; do s[k]=s[k+1]; while(s[++k]!=0); }else i++; } } //Ð m t trong xâu int demtu(char *s) { int d=0; int len=strlen(s); if (s[0]!=' ') d++; for(int i=0;i<=len;i++) if(s[i]==' ' && s[i+1]!=' ') d++; return d; } void main() { char s[100]; cout<<"Nhap xau"; gets(s); rtrim(s); ltrim(s); ctrim(s); cout<<"!!"<<s<<"!!"; cout<<" \ nSo tu:"<<demtu(s)<<endl; }

Ngày đăng: 09/07/2014, 10:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan