0

The same way, the problem continues, the printf only confirmed that appears a letter "mysterious" in the last line =s

0

Now run this:

        while(fgets(string, sizeof(string), p) != NULL )
            {
printf("%s", string);
              choppy(string);
printf("%s\n", string);
              cop(string, a2);
printf("%s\n", string);
              strcat(a2, nameyes);
              cop(string, a3);
printf("%s\n\n", string);
              strcat(a3, nameno);
              func(string, namesearch, nameend, a2, a3);
            }

Edited by Ancient Dragon

0

It seems that when it reaches the last line of the file, the program's has a problem. He repeats the line without giving a "\n" as commanded, and there comes the mysterious character

0

Does the input text file have a cr after the last line? If not, put one there and retest. If not then the proglem has to be choppy() -- the last line may not have '\n' at the end of the line.

void choppy( char *s )
{
   char *ptr = strrchr(s,'\n');
   if( ptr != NULL)
       *ptr = ' ';
}

[edit]I removed the last CR from my file and got lots of junk in r.txt file, for the reason I mentioned previously. The new version of choppy() fixed the problem.

Edited by Ancient Dragon

0

It did not work, with this choppy it took the space " " that exists in the last row

0

it took the space " " that exists in the last row

Huh? The function does nothing if there is no '\n' in the string. If you want a space there then modify the function to append a space if there is no '\n'.

Edited by Ancient Dragon

0

looks like the file was. The last row.

Attachments
rice milk bread bread_yes 
apple sweet tomato bread_no 
Watermelon tomato onion bread_no 
tomato cheese bread bread_yes 
curd chocolate bread bread_yes 
Chocolate Milk Watermelonbread_no
0

Thanks for the replies. I managed to find a solution (I think kkk). I wiped the computer, and the program just worked. '-'

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.