Ok, here's what I've got. As per my assignment instructions, it actually just uses I/O redirection. However, I'm having some errors:
Code:
#include <stdio.h>
char input [30];
int stack [30];
char c;
int cnt = 0;
int main ()
{
while ((c = getchar()) != '-1')
{
if (c != '\n')
{
input[cnt++] = c;
}
if (c == '\n')
{
puts(input);
printf("Flip would be here.\n");
cnt = 0;
}
}
}
Input.txt is as follows:
Code:
1 4 7 5 2 5
8 5 3 2 6 4 1 2 9 10 2
6 9 16 8 4
-1
And the output is:
Code:
1 4 7 5 2 5
Flip would be here.
8 5 3 2 6 4 1 2 9 10 2
Flip would be here.
6 9 16 8 44 1 2 9 10 2
Flip would be here.
-19 16 8 44 1 2 9 10 2
Flip would be here.
Segmentation fault
So, the problem here is that it seems to keep reading after it hits -1, and it doesn't clear the string. What am I missing here?