This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/59598] very simple code using file open for read
- From: "Denis dot V dot Kolesnik at safe-mail dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 26 Dec 2013 19:50:57 +0000
- Subject: [Bug c++/59598] very simple code using file open for read
- Auto-submitted: auto-generated
- References: <bug-59598-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59598
Denis Kolesnik <Denis.V.Kolesnik@safe-mail.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #6 from Denis Kolesnik <Denis.V.Kolesnik@safe-mail.net> ---
please tell me where in this corrected code I made mistake:>
// a small text file filter.c //
#include <stdio.h>
main(int argc, char* argv[])
{
char c, previous_c;
int word_begin_position[3000];
int spec_symbol[7]={0xAE,0xBB,0xAB,0xA9,0x22,0x2F,0x27};
int eof_symbol[2]={0x0D,0x0A};
int search_result;
int this_is_the_same_word;
int words_count;
int word_number;
int search_result_A_count;
int search_result_space;
FILE *stream,*stream2;
int i, j, characters_count, character_number;
characters_count=0;
stream = fopen (argv[1],"r");
while ((c = fgetc(stream)) != EOF)
{
characters_count++;
}
fclose(stream);
//printf("total characters are %i\n", characters_count);
character_number=1;
words_count=0;
previous_c=0;
stream = fopen (argv[1],"r");
while ((c = fgetc(stream)) != EOF)
{
if(((c!=0x20) && (character_number==1)) || ((previous_c==0x20) &&
(c!=0x20) && (c!=0x0A)) || ((previous_c!=0x20) && (c==0x0D)) || ((c!=0x20) &&
(c!=0x0D) && (c!=0x0A) && (previous_c==0x0A)) || ((previous_c!=0x20) &&
(previous_c!=0x0A) && (character_number==characters_count) && (c==0x20)))
// 1. ((c!=0x20) && (character_number==1))
// 2. ((previous_c==0x20) && (c!=0x20) && (c!=0x0A))
// 3. ((previous_c!=0x20) && (c==0x0D))
// !((previous_c!=0x0D) && (c==0x0A))
// 4. ((c!=0x20) && (c!=0x0D) && (c!=0x0A) && (previous_c==0x0A))
// 5. ((previous_c!=0x20) && (previous_c!=0x0A) &&
(character_number==characters_count) && (c==0x20))
this_is_the_same_word=0;
else
this_is_the_same_word=1;
if(this_is_the_same_word==0)
{
words_count++;
word_begin_position[words_count]=character_number;
//printf(" the begin char is .....
%i",word_begin_position[words_count]);
}
//if(character_number==characters_count)
// printf("the last character");
/*
printf(" the number of words is %i\n", words_count);
printf(" the current character is ..... %c\n", c);
if(c==0x0D)
printf(" the current character is ..... 0x0D\n");
if(c==0x0A)
printf(" the current character is ..... 0x0A\n");
*/
previous_c=c;
character_number++;
}
fclose(stream);
word_number=1;
character_number=1;
stream = fopen (argv[1],"r");
//stream2 = fopen (argv[2],"w");
while ((c = fgetc(stream)) != EOF)
{
//if((character_number >= word_begin_position[word_number]) &&
(character_number <= word_begin_position[word_number+1]))
if(c==0x0D)
then
{
//fprintf(stream2,"%s", "\\r\\n");
// if(c==EOF)
// then
// printf("A");
// else
// printf("%s",c);
printf("%s", c);
}
// else
// word_number++;
character_number++;
}
fclose(stream);
//printf(" the number of words is %i", words_count);
return 0;
}
why this portion of code:>
if(c==0x0D)
then
{
//fprintf(stream2,"%s", "\\r\\n");
// if(c==EOF)
// then
// printf("A");
// else
// printf("%s",c);
printf("%s", c);
}
// else
// word_number++;
reports:>
replace_1.c: In function 'main':
replace_1.c:112:3: error: 'then' undeclared (first use in this function)
replace_1.c:112:3: note: each undeclared identifier is reported only once for
ea
ch function it appears in
replace_1.c:113:3: error: expected ';' before '{' token