0

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

Edited by COKEDUDE

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by L7Sqr
0

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.

This topic has been dead for over six months. 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.