samedi 1 octobre 2016

Creating loops to read an ascii (.txt) file by piping it into a program and then outputting it into another file

I am trying to essentially pipe a .txt ascii file into a program. My program needs to be able read the lines upon lines of ascii code and then output what it reads into a file. At which point i will compare the file I just filled with ascii to another file which has the correct output of the file already using the diff command. I am really new to C (it's my third week, with once a week lab instruction time with my prof), and I feel I'm quite close to figuring this out, but i feel the nesting of my loops is off.

Any help would be appreciated.

int main(void) {
char character;
int length;
int i;
// loop until the end of input sentinel is seen
while ( 1 )
{
    // get the first element in the line
    scanf("%d%c", &length, &character);

    if(length == -1)
    {
break;
}
else
{



// is it the sentinel? if so, then break out of the loop



    // reconstruct a line, as per part 2
            while ( length != -1 )
            {

            for( i = 0; i<= length; i++)
            {
                    printf("%c", character);
            }
            scanf("%d%c", &length, &character);
            }
            printf("\n");
    }
}

return 0;

}

Aucun commentaire:

Enregistrer un commentaire