我现在已经读了这本书超过两个星期了,这是我得到的(非常慢,对吗?)无论如何这就是我所做的:
我尝试使用eclipse编译时得到这个
Building file: ../main.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
../main.c: In function ‘erasewhites’:
../main.c:59:1: error: expected declaration or statement at end of input
}
^
../main.c:59:1: warning: control reaches end of non-void function [-Wreturn-type]
}
第59行表示"至[i] =来自[i]" 我试图做的是读取并将其复制到矢量,然后将该矢量复制到一个没有白色空格和标签的新矢量,然后如果它不是一个空行,主函数应该打印它。我正在寻找这个错误,但我发现的唯一的事情是有一个回复缺失,我已经想到但它是一个无效的功能(复制(到[],从[]))我试过写}令牌返回;并返回0;但一直得到同样的错误 这个想法是否接近于练习所要求的内容? (练习1-18。编写程序以从每行输入中删除尾随空白和制表符,以及 删除完全空行。 ) 谢谢!
#include <stdio.h>
#define MAXLINE 1000
#define BLANK 1
#define NOT_BLANK 0
int getlinea (char s [], int lim);
void copy (char to [], char from []);
int erasewhites (char s[], int len);
int main (void){
char palabra [MAXLINE];
int len;
while ( (len = getlinea (palabra, MAXLINE) ) >= 0)
if (len > 0)
printf ("%s\n",palabra);
return 0;
}
int getlinea (char s[], int lim){
int i, c, len;
char aux[MAXLINE];
for ( i=0; ( c = getchar () )!= EOF && c != '\n' && i < lim-1 ; ++i)
aux[i] = c ;
if (c == EOF)
return -1;
if ( ( len = erasewhites ( aux, i) ) > 0 )
copy ( s , aux );
else
return 0;
return len;
}
int erasewhites (char s[], int len){
int state = BLANK;
while (len > 0 && state == BLANK){
if ( s[len] != 32 && s[len] != '\t' )
state = NOT_BLANK;
else
--len;
}
if ( len >= 0 )
s[len+1] = '\0';
else
return 0;
return len;
}
void copy ( char to[], char from [] ){
int i;
for ( i = 0 ; from [i] != '\0' ; ++i)
to [i] = from [i] ;
to [i+1] = '\0';
}
我删除了注释的行并编译了......这很奇怪,这就是我去的时候终端返回
$ ./program< main.c中
#include <stdio.h>td
#define MAXLINE 1000
#define BLANK 1 1000
#define NOT_BLANK 00
int getlinea (char s [], int lim);
void copy (char to [], char from []);
int erasewhites (char s[], int len);;
int main (void){(char s[], int len);;
char palabra [MAXLINE];], int len);;
int len;abra [MAXLINE];], int len);;
while ( (len = getlinea (palabra, MAXLINE) ) >= 0)dԁ
if (len > 0)= getlinea (palabra, MAXLINE) ) >= 0)dԁ
printf ("%s\n",palabra);alabra, MAXLINE) ) >= 0)dԁ
return 0;("%s\n",palabra);alabra, MAXLINE) ) >= 0)dԁ
}return 0;("%s\n",palabra);alabra, MAXLINE) ) >= 0)dԁ
int getlinea (char s[], int lim){, MAXLINE) ) >= 0)dԁ
int i, c, len;har s[], int lim){, MAXLINE) ) >= 0)dԁ
char aux[MAXLINE];s[], int lim){, MAXLINE) ) >= 0)dԁ
for ( i=0; ( c = getchar () )!= EOF && c != '\n' && i < lim-1 ; ++i)��0)z�
aux[i] = c ;c = getchar () )!= EOF && c != '\n' && i < lim-1 ; ++i)��0)z�
if (c == EOF)c = getchar () )!= EOF && c != '\n' && i < lim-1 ; ++i)��0)z�
return -1;F)c = getchar () )!= EOF && c != '\n' && i < lim-1 ; ++i)��0)z�
if ( ( len = erasewhites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
copy ( s , aux );whites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
elsey ( s , aux );whites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
return 0;, aux );whites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
return len; aux );whites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
}return len; aux );whites ( aux, i) ) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
int erasewhites (char s[], int len){) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
int state = BLANK;ar s[], int len){) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
while (len > 0 && state == BLANK){{) > 0 )= '\n' && i < lim-1 ; ++i)��0)z�
if ( s[len] != 32 && s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
state = NOT_BLANK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
elsete = NOT_BLANK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
--len;= NOT_BLANK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
} --len;= NOT_BLANK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
if ( len >= 0 )LANK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
s[len+1] = '\0';NK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
elseen+1] = '\0';NK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
return 0;= '\0';NK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
return len; '\0';NK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
}return len; '\0';NK;& s[len] != '\t' ) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
void copy ( char to[], char from [] ){) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
int i;py ( char to[], char from [] ){) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
for ( i = 0 ; from [i] != '\0' ; ++i)) 0 )= '\n' && i < lim-1 ; ++i)��0)z�
to [i] = from [i] ;i] != '\0' ; ++i)) 0 )= '\n' && i < lim-1 ; ++i)��0)z�