字符数组变量nspace大小等于10的时候正常,但是等于1或2的时候就不正常了 。
测试输入(以下的制表符可能变成空格了):
代码:
meet you how are you i am fine thank you and you? very well what meet you how are you iam fine thank you and you? very well what meet you how are you i am fine thank you and you? very well what meet you how are you i am fine thank you and you? very well what meet you how are you i am fine thank you and you? very well what meet you how are you i am fine thank you and you? very well
这段代码用来分割输入的行,并把制表符换成多个空格,5列后分行
代码:
#include
#define MAXLINE 10000
int main(){
char input[MAXLINE];
getline1(input,MAXLINE);
int i,l;
int n=5;
int currenttab=0;
char nspace[2]={' ',' '};
char s[10];
int k=0;
for(i=0;i
//printf("%c\n",input[i]);
if(input[i]!='\t'){
s[k]=input[i];
k++;
}
else{
s[k]='\0';
printf("%10s",s);
k=0;
currenttab++;
printf("%s",nspace);
if((currenttab%n)==0)
printf("\n");
}
}
printf("\n");
}
int getline1(char s[],int lim){
int i;
char c;
for(i=0;i
s[i]=c;
}
if(c=='\n'){
s[i]=c;
i++;
}
s[i]='\0';
return i;
}