Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

printing the graph in a output file using c language

Need solution for printing a graph in a output file either txt or another file using c language
0
mindboom
Asked:
mindboom
  • 6
  • 6
1 Solution
 
Infinity08Commented:
What kind of graph ?
For what purpose ?
Which part is it that you have trouble with ?
0
 
mindboomAuthor Commented:
i am able to get the output in command prompt... i need tat to be displayed on a text file... i am facing problem with it... can anyone give a suggestion along with a sample code how to print the graph on a text file...
0
 
mindboomAuthor Commented:
graph for finding the mainchain of a atom... in pixel format.... getting problem to displaying in txt format
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Infinity08Commented:
>> i am able to get the output in command prompt... i need tat to be displayed on a text file...

Then the easiest solution is to re-direct the standard output to a file, by starting the program like this :

        ./program your_arguments > textfile.txt

The standard output will now no longer be written to the screen, but to the given textfile.txt.


You can obviously modify your code to write to a file rather than standard output. You'd have to use fopen and fclose to open and close a file resp. And you can replace all your printf calls with fprintf calls to write to the opened file.

        http://cplusplus.com/reference/clibrary/cstdio/fopen/
        http://cplusplus.com/reference/clibrary/cstdio/fclose/
        http://cplusplus.com/reference/clibrary/cstdio/fprintf/
0
 
mindboomAuthor Commented:
i need a sample code format... i used fprintf...but it seems not working oor me to print the pixel in the text file....
0
 
Infinity08Commented:
What do you mean by "print the pixel" ? Weren't you talking about a text file ?

Can you show your code ?
0
 
mindboomAuthor Commented:
sure... i will show u the code... i need to print the total output of the graph with all the pixel  in  a text file.
#include<stdio.h>
#include<stdlib.h>
#include"graphics.h"
#include<math.h>
#include<conio.h>
#include<stdlib.h>
 
#define TRUE 1
#define FALSE 0
 
char x_axis1[10], y_axis1[10];
 
char characterSet[2][1];
 
float a[2][1];
 
struct DataStructure
{
char value[3];
char alpha[3];
char floatingNumber1[7];
char floatingNumber2[10];
char floatingNumber3[10];
char characters[7];
}DataStruct;
 
void LeftTrim(char string[], char axis[])
{
	int i, j=0;
	int foundSpaceBeforeValue=0, foundValue=FALSE;
	for (i = 0; i<strlen(string); i++)
	{
		if(string[i] == 14)
		{
			if(foundValue == TRUE)
				goto Exit;
			else
				foundSpaceBeforeValue++;
		}
		else if(string[i] != 14)
		{
			foundValue = TRUE;
			axis[j++] = string[i];
		}
	}
	Exit: return;
}
 
int StringCompare(const char *s1, const char *s2)
{
    unsigned char uc1, uc2;
 
    /* Move s1 and s2 to the first differing characters
       in each string, or the ends of the strings if they
       are identical.  */
    while (*s1 != '\0' && *s1 == *s2) {
	s1++;
	s2++;
    }
    /* Compare the characters as unsigned char and
       return the difference.  */
    uc1 = (*(unsigned char *) s1);
    uc2 = (*(unsigned char *) s2);
    if (uc1 != uc2)
       return ((uc1 < uc2) ? -1 : (uc1 > uc2));
    else
       return 0;
}
 
void AssignNull(char *s1)
{
	while(*s1 != '\0')
		*s1 = NULL,s1++;
}
 
 
void ReadingFiles(char outputFileName[])
{
	FILE *ifile, *ofile;
	int i = 0;
	int gd=DETECT,gm;
	float x,y,p,q;
 
	long curpos;
	char readLine[40];
	initgraph(&gd,&gm,"c:\\tc\\bgi");
 
	 setfillstyle(SOLID_FILL,WHITE);
    bar(0, 0, 639, 480);
    setcolor(1);
    line(320,40,320,400);
    line(140,40,140,400);
    line(500,40,500,400);
    line(140,40,500,40);
    line(140,400,500,400);
    line(140,220,500,220);
    //biforcations:
    setcolor(7);
    line(410,40,410,400);
    line(230,40,230,400);
    line(140,130,500,130);
    line(140,310,500,310);
    //writings:
    setcolor(1);
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(90,30,"+180");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(80,120,"+psi");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(120,220,"0");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(80,320,"-psi");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(90,405,"-180");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(120,420,"-180");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(200,430,"-phi");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(315,420,"0");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(400,430,"+phi");
    settextstyle(1,HORIZ_DIR,1);
    outtextxy(470,420,"+180");
 
	if ((ifile = fopen ("angl.txt","r")) == NULL)
	{
		perror("angl.txt");
		printf("Exiting program!");
		getch();
		exit(1);
	}
	else
	{
		ofile = fopen (outputFileName,"w");
		while (!feof(ifile))
		{
			fread(&DataStruct, sizeof(DataStruct), 1, ifile);
		 //	printf("%s\n", DataStruct.a);
		 //	AssignNull(characterSet[i]);
		 //	LeftTrim(DataStruct.lineNumber, characterSet[i]);
 
				if (i == 0)
				{
					LeftTrim(DataStruct.floatingNumber1, x_axis1);
					LeftTrim(DataStruct.floatingNumber2, y_axis1);
				      //	LeftTrim(DataStruct.floatingNumber3, z_axis1);
 
					a[0][0] = atof(x_axis1);a[1][0] = atof(y_axis1);
					x=a[0][0];
					y=a[1][0];
 
					if(x>0)
					{
					 p=320+x;
					 }
					 else
					 p=320-x;
 
					if(y>0)
					{
					 q=220-y;
					}
					else
					q=220+y;
 
					putpixel(p,q,4);
				}
 
					sprintf(readLine, "First Atom: %f\t%f\n", a[0][0], a[0][1]);
					fputs(readLine, ofile);
			}
		}
		fclose(ofile);
		fclose(ifile);
	}
 
 
void main()
{
	int i, j;
	int gd,gm;
 
 
	clrscr();
 
	ReadingFiles("ram.txt");
  //	ReadingFiles(1, "psiSeries.txt");
 
   //	initgraph(&gd,&gm,"c:\\tc\\bgi");
 
     //	putpixel(10,10,4);
}

Open in new window

0
 
Infinity08Commented:
You're using graphical output. How do you want to put that in a text file ?

What you probably want to do, is use an image manipulation library, like Cairo (http://cairographics.org/) or ImageMagick (http://www.imagemagick.org/script/index.php).
0
 
mindboomAuthor Commented:
but how to print the graphical output on a text file???
0
 
Infinity08Commented:
>> but how to print the graphical output on a text file???

What do you mean ? A text file is for text data, not for graphical data.
0
 
mindboomAuthor Commented:
graphical output on a text file nor excel....
0
 
Infinity08Commented:
???
As I said : a text file is for text data, NOT for graphical data.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now