Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

printing the graph in a output file using c  language

Posted on 2009-05-07
13
Medium Priority
?
623 Views
Last Modified: 2012-05-06
Need solution for printing a graph in a output file either txt or another file using c language
0
Comment
Question by:mindboom
  • 6
  • 6
13 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24325341
What kind of graph ?
For what purpose ?
Which part is it that you have trouble with ?
0
 

Author Comment

by:mindboom
ID: 24333088
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
 

Author Comment

by:mindboom
ID: 24333171
graph for finding the mainchain of a atom... in pixel format.... getting problem to displaying in txt format
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 24333425
>> 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
 

Author Comment

by:mindboom
ID: 24333785
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 24334072
What do you mean by "print the pixel" ? Weren't you talking about a text file ?

Can you show your code ?
0
 

Author Comment

by:mindboom
ID: 24334283
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 24334485
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
 

Author Comment

by:mindboom
ID: 24334619
but how to print the graphical output on a text file???
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24334685
>> 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
 

Author Comment

by:mindboom
ID: 24334719
graphical output on a text file nor excel....
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 80 total points
ID: 24334851
???
As I said : a text file is for text data, NOT for graphical data.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question