hi,
i think i have solved ur problem. ur problem if i have understood is how to use fprintf in ur code. it is very simple buddy just some kind of a logic is required and u can do it......
ur whole code goes like this..............
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char line[101], filename[101];
char*line_ptr;
struct node
{
int id;
double x, y;
};
struct node node_array[100];
int no_nodes = 0, no_values=0;
FILE*input_stream;
fprintf(stdout, "Enter file name:");
fscanf(stdin, "%s", filename);
if ((input_stream = fopen(filename, "r")) !=NULL)
{
fgets(line, sizeof(line), input_stream);
while((line_ptr = fgets(line, sizeof(line), input_stream))!=NULL)
{
if((no_values = sscanf(line, "%d %lf %lf",&node_array [no_nodes].id,&node_array [no_nodes].x,&node_array [no_nodes].y))==3)
{
no_nodes++;
}
if ((line_ptr !=NULL)&&(no_values !=3))
fprintf(stdout, "Error reading line %s\n", line);
else if(line_ptr==NULL)
fprintf(stdout, "End of file found\n");
else
fprintf(stdout,"%d %lf %lf\n",node_array [no_nodes-1].id,node_array [no_nodes-1].x,node_array [no_nodes-1].y);
}
}
system("pause");
}
i think this will work for u and hope i i have solved ur problem sucessfully
bye
Praveen