GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Apr-2005, 20:43
DesperateCry DesperateCry is offline
New Member
 
Join Date: Mar 2005
Posts: 10
DesperateCry is on a distinguished road

Writing to Text Files


I need to find if two lines formed from the points i read from a text file intersects and write the intersected points number, x,y coordinates back to the same file. So far still no luck... I neither could get the x, y found in kesisim function to main function, nor write them right into the file at the function.. At the last try, i got a file of some megabytes...

CPP / C++ / C Code:
#include <stdio.h>


float kesisim(float a, float b, float c, float d, float e, float f, float g, float h, int sira)
{
        
        float i,j,k,l,m,n;
        FILE* fp;
        i = d - b;                         //30
        j = c - a;
        k = i / j;
        l = h - f;
        m = g - e;
        n = l / m;                   //35
    printf("dogru icinde\n");
        if ( a == c && a == e && e == g )
           printf("Tüm noktalar ayni dogru üzerindedir\n");
        else if ( b == d && b == f && f == h )
           printf("Tüm noktalar ayni dogru üzerindedir\n");     //40
        else if ( k != n )
        {
           float A, B, C, D, E, F, G, x, y;          //43
           A = b - d;
           B = c - a;
           C = A*a+B*b;
           E = f - h;
           F = g - e;                      //48
           G = E*e+F*f;
           D = A*F - E*B;
           x = ( F*C - B*G )/D;
           y = ( A*G - E*C )/D;
           printf("Dogrular x = %f, y = %f noktasinda kesisirler\n", x, y);
           fp = fopen("deneme.txt","w");    //70
           while(!feof(fp))
           {
            fprintf(fp,"%d %f %f\n", sira, x, y);
           }
        }
        else
        printf("Dogrular Kesismez\n");
        fclose(fp);
        return 0;    
}

                                          //60
int main()
  
{

  int    n[100];
  float  x[100];
  float  y[100];      //65
  FILE* fp;
  int indis,no,v,w,p,z;
  int no1, no2, no3, no4;
  float o1, o2;
  int o,q;
  o = 0;
  fp = fopen("deneme.txt","r");    //70

  while(!feof(fp))
    {

    printf("#%d\n",o);            //75
    fscanf(fp,"%d",&n[o]);
fscanf(fp,"%f",&x[o]);
fscanf(fp,"%f\n",&y[o]);

    printf("Point %d: %f,%f\n",n[o],x[o],y[o]);
    o++;
    
    }                  //80
  
  printf("%f\n", x[9]);
  printf("Enter 4 points by numbers\n");
  scanf("%d %d %d %d\n", &no1,&no2,&no3,&no4);
  fclose(fp);
  q=o+1;
  kesisim(x[no1], y[no1], x[no2], y[no2], x[no3], y[no3],x[no4],y[no4],q);
  return 0;                //85
}
  #2  
Old 13-Apr-2005, 01:19
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by DesperateCry
I need to find if two lines formed from the points i read from a text file intersects and write the intersected points number, x,y coordinates back to the same file. So far still no luck... I neither could get the x, y found in kesisim function to main function, nor write them right into the file at the function.. At the last try, i got a file of some megabytes...
You might want to tell us what happened and what you expected to happen. Your description gives us no clue other than "it don't work right". Also, use two different files during testing so you don't have to recreate the input file all the time.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 19-Apr-2005, 08:09
DesperateCry DesperateCry is offline
New Member
 
Join Date: Mar 2005
Posts: 10
DesperateCry is on a distinguished road
Quote:
Originally Posted by WaltP
You might want to tell us what happened and what you expected to happen. Your description gives us no clue other than "it don't work right". Also, use two different files during testing so you don't have to recreate the input file all the time.

Sorry, i was able to solve the problems afterwards. Now that reads the point numbers, x,y coordinates from a file, let you choose four points by numbers, form two lines from them and write down the intersection point (if there is) in the same file. Currently working on some details, like entering same numbers, entered point number not existing in the file to be read, giving number to the new point to be written.. Indis is belong to these details, well after i will write down them

CPP / C++ / C Code:
#include <stdio.h>


float kesisim(float a, float b, float c, float d, float e, float f, float g, float h, float sira)
{
        
        float i,j,k,l,m,n;
        FILE* fs;
        i = d - b;                         //30
        j = c - a;
        k = i / j;
        l = h - f;
        m = g - e;
        n = l / m;                   //35
        if ( a == c && a == e && e == g )
           printf("Points are on the same line\n");
        else if ( b == d && b == f && f == h )
           printf("Points are on the same line\n");     //40
        else if ( k != n )
        {
           float A, B, C, D, E, F, G, x, y;          //43
           A = b - d;
           B = c - a;
           C = A*a+B*b;
           E = f - h;
           F = g - e;                      //48
           G = E*e+F*f;
           D = A*F - E*B;
           x = ( F*C - B*G )/D;
           y = ( A*G - E*C )/D;
           printf("Lines intersect at x = %f, y = %f\n", x, y);
           fs = fopen("deneme.txt","a");    //70
           {
            fprintf(fs,"%f %f %f", sira, x, y);
           }
        fclose(fs);
        }
        else
        printf("Lines does not intersect\n");
     
        return 0;    
}

                                          //60
int main()
  
{

  int    n[100];
  float  x[100];
  float  y[100];      //65
  FILE* fp;
  int indis,no,v,w,p,z;
  int no1, no2, no3, no4;
  float o1, o2;
  int o,q;
  o = 0;
  fp = fopen("deneme.txt","r");    //70
  while(!feof(fp))
    {

    printf("#%d\n",o);            //75
    fscanf(fp,"%d",&n[o]);
fscanf(fp,"%f",&x[o]);
fscanf(fp,"%f\n",&y[o]);

    printf("Point %d: %f,%f\n",n[o],x[o],y[o]);
    o++;
    
    }                  //80
 
  printf("%f\n", x[9]);
  do{
  printf("Enter 4 points by numbers\n");
  scanf("%d %d %d %d", &no1,&no2,&no3,&no4);
  }while(no1==no2 || no1==no3 || no1==no4 || no2==no3 || no2==no4 || no3==no4);
  if(no1==n[q])
  indis=q;
  printf("%d\n", q);
  fclose(fp);
  kesisim(x[no1], y[no1], x[no2], y[no2], x[no3], y[no3],x[no4],y[no4],o);
  return 0;                //85
}
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting text files to html files kensenb C Programming Language 13 09-Nov-2004 12:33
phpmyadmin--what format for text files to upload? bufhal MySQL / PHP Forum 0 04-Jul-2004 11:07
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
Manipulating text Files k209310 C++ Forum 0 17-Nov-2003 11:23

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:24.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.