[Bug c++/59598] very simple code using file open for read
Denis.V.Kolesnik@safe-mail.net
gcc-bugzilla@gcc.gnu.org
Thu Dec 26 20:11:00 GMT 2013
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 #11 from Denis Kolesnik <Denis.V.Kolesnik@safe-mail.net> ---
why in this code:>
// 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)
printf("A");
else
printf("%s", c);
}
// else
// word_number++;
character_number++;
}
fclose(stream);
//printf(" the number of words is %i", words_count);
return 0;
}
the portion:>
if(c==0x0D)
printf("A");
else
printf("%s", c);
results in error while program run??
More information about the Gcc-bugs
mailing list