Here is my code that is doing the printing that gets messed up. The output is fine when you display it to your screen (terminal). Unfortunately when you redirect it to a text file it gets messed up. It displays the null characters (^@) and Enquiry characters (^E). I have to use a for loop like this or my outputs gets messed up. I can't use the %s option or my output won't be in the way I need it.

FILE *input;
char line[80] = {0};
while(fgets(line, 80, input) != NULL)
{
    if((int)line[0] == 46)
    {
        //printf("You have a period \n");
        for(i = 31; i < 80; i++)
        {
            printf("%c", line[i]);
        }
        //printf(" ------------------------\n");
        memset(line, 0, 80);
        comment_flag = 1; 
    }
}

You do not assign anything to input; it is a raw pointer (in your example). If you try to read from an arbitrary location in memory the best you are going to get are strange characters in your output. Try reading from stdin or opening a file stream with fopen.

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.