If you want to continue processing something after you have printed it out, make sure that the variable that holds the data stays in scope.
Take for instance a function like:
void sample_function (void) {
int data;
scanf("%d\n", &data);
printf("The input was: %d\n", data);
}
After print out the value of data
, you can't do anything else with it. You reach the end of the function and when the function returns, the data that lives inside the scope of that function is freed.
It is possible to use that data after the function has returned, but you have to change your technique a bit. One possibility is to make data
a global variable instead of a local variable inside the function. You can also pass back the value of data
using the return value of the function, or you can pass an int*
to the function and have the function store the data using that pointer. With any of these techniques, you should be able to call a function like sample_function
and keep the data in scope after the function has returned.
As long as the variable holding the data doesn't go out of scope, you shouldn't have much of a problem re-using your data over and over again. Printing/displaying the data doesn't alter or destroy it, the only way that you can lose the ability to re-use the data is if the variable holding the data gets destroyed (by going out of scope or by being being free
d).
From your description, it's hard to get a good picture of what exactly you are talking about. Can you give us an example (in code) of a situation like you are talking about?
Update:
Based on your edits, it looks like you are not completely understanding what is happening. When you print data to the screen, you are not altering the data at all. You still have every ability to modify, access, and re-use the data just as you did before you displayed it. You shouldn't have to do anything in particular to use the data again. Using one of your examples, let's say you have an array that contains a series of numbers in a Fibonacci sequence:
int sequence[100];
int i, sum;
fill_with_fibonacci_sequence(sequence); // or however else you get your initial data
// Print out the sequence
printf("The Fibonacci sequence is: ");
for (i=0; i<100; ++i) {
if ((i & 0x7) == 0)
printf("\n ");
printf("%i ", sequence[i]);
}
// Sum all of the even numbers from the sequence
sum = 0;
for (i=0; i<100; ++i) {
if ((sequence[i] & 0x1) == 0)
sum += sequence[i];
}
printf("The sum of the even numbers is: %i\n", sum);
Here, we print each value in the array, then turn around and re-process the array in order to sum the even terms. Printing out the array doesn't change the array itself, so nothing special needs to be done in order to re-use the data.