+ 1

How can i store the result printed on output screen in c or c++ language??

How to save output values in data types to use them again

7th May 2020, 2:52 PM
Nikhil Sharma
Nikhil Sharma - avatar
7 Réponses
+ 2
You can replace printf() with snprintf() to store the formatted output in strings instead of printing to the console.
7th May 2020, 7:17 PM
Brian
Brian - avatar
+ 1
You couldn't get my point Basically i made a program for infix to postfix expression conversion. After printing the postfix expression on the output screen. I want to use this result to evaluate this expression using real numbers.different functions of my programs print single values one by one in a randomised manner. So i just simply want to store the output i get on the screen as a string in a char array instead of inserting values one by one in each function i made using array,queue or a stack. Now u got my point??
7th May 2020, 3:14 PM
Nikhil Sharma
Nikhil Sharma - avatar
+ 1
Not so clear still.. If you can share that code, then I may give you a possible way.. You can use charecter array to store everytime a charecter result.. It depends on how you producing results...
7th May 2020, 3:23 PM
Jayakrishna 🇮🇳
+ 1
Nikhil Sharma just before printing the value, just like Jayakrishna🇮🇳 said, store it in character array.
7th May 2020, 3:46 PM
Arsenic
Arsenic - avatar
+ 1
Nikhil Sharma this is an example what I mean.. This is what you're looking for.. #include<string.h> #include<stdio.h> int main() { char s[300]; int n=0; for(int i=1; i<5; i++) { for(int j=1; j<5; j++) {for(int k=1; k<5; k++) { s[n++]=(char)i; s[n++]=(char)j; s[n++]=(char)k; printf("%d%d%d\n",i,j,k); } } } for(int i=0;i<strlen(s);i+=3) printf("\n%d%d%d",s[i],s[i+1],s[i+2]); return 0; } The last printf prints the same which is result of first 2 loop's produced result and displayed..
7th May 2020, 7:22 PM
Jayakrishna 🇮🇳
0
Can't you store the result in related data type variables before printing.. Are know about variable? If not, read about it.. Ex: int a=3,b=5; int c=a*b; printf("%d", c);..
7th May 2020, 3:09 PM
Jayakrishna 🇮🇳
0
Like,output screen give me a new result which was not predictable or not supposed to present in the print statements. So i wanted to save it in an array.
7th May 2020, 3:16 PM
Nikhil Sharma
Nikhil Sharma - avatar