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

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);
            }

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

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.

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

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'.

looks like the file was. The last row.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.