- Khóc Thầm đã viết:
- Bạn cứ thử với thật nhiều dấu space liên tiếp nhau đi
ak ừ, mình hiểu ý bạn rồi. Mình copy thiếu mất 1 dòng bạn thêm dòng
- Code:
-
i--;
trước đoạn
- Code:
-
k++;
là được thôi
code đầy đủ
- Code:
-
#include<iostream.h>
#include<conio.h>
#include<string.h>//Header file processing String
//Starting my function to delete while space//
void del(char a[])//Function delete while Space
{
int k=0,m=0;
int len=strlen(a);
for(int i=0;i<strlen(a);i++)
{
if(a[i]==' ')//if a[i] is while space we will delete it
{
for(int j=i+1;j<strlen(a);j++)
{
a[j-1]=a[j];//Change place
} i--;
k++;
a[len-k]='\0';//Assign the end of string as Null value
}
}
}
//The end of function
void main()//Main program
{
clrscr();// ClearScreen
int index;
char s[100];
cout<<"Type your String to process: ";
cin.getline(s,100);
cout<<"The first string:"<<s<<endl;
del(s);
cout<<"Your string after processing: "<<s;
getch();//StopScreenToWatch
}
thanks ban đã đọc