Thread: Having a hard time understanding FILES!

  1. #1
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38

    Having a hard time understanding FILES!

    Help!! I don't understand FILES at all and the scientific terms used by FAQ only confuses me more!!!

    I do know how to use FILES though, what I don't understand is how to save the user's input and the computer's output without overlapping the past I/O?

    Did anyone get my point? Thanks in advance for those who'll help me...

    TO ALL THOSE WITH FRIENDSTER, ADD ME!

    i'm [email protected]
    a newbie in the field of Computer Science!! Pray for all the student's success!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What don't you understand? You say you don't understand them, but you know how to use them. Which is it?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    let me rephrase my question...

    I understand only a LITTLE of how FILES work. I know that if you want to open a file, you use fopen() and if you close, fclose(); r is for read, r+ is for read and write (i think) and so on and so forth. I already made a program that'll save a reader's input but whenever I want to ask the user a different input, the second input overlaps the first input. Now, why's that?






    4gv me 4 being incredibly stupid and confusing....

    TO ALL THOSE WITH FRIENDSTER, ADD ME!

    i'm [email protected]
    a newbie in the field of Computer Science!! Pray for all the student's success!

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Probably because you keep opening it in write mode, which truncates the file (positioning the file pointer to the beginning at opening) when you write to it. Read the man page for fopen to get a full listing of all of the modes. You'd be advised to get a good C reference book which covers the standard and its libraries in detail.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by nesir
    let me rephrase my question...

    I understand only a LITTLE of how FILES work. I know that if you want to open a file, you use fopen() and if you close, fclose(); r is for read, r+ is for read and write (i think) and so on and so forth. I already made a program that'll save a reader's input but whenever I want to ask the user a different input, the second input overlaps the first input. Now, why's that?






    4gv me 4 being incredibly stupid and confusing....
    Here is a little program I wrote recently, it opens one file "25_10_v.txt" and finds the sum of two columns of numbers (one floating point, one integer, at column positions 7 and 28) and writes the totals into another file "25_10_add.txt", note that I open this file for "w" (write). You might find this helpful as an example. I am not saying it is a great example of programming style/standards etc.. but it did work
    Maybe you will find it helpful?

    I have programed a lot over the years and I can say I have never used r+!!!
    The reason I do this is because you risk screwing up your input file!! And if you have not backed it up first you could lose a whole lot of data!! (probably), best to err on the safe side and verify that the output file is correct before you write over/into the input file.



    Code:
    #include <stdio.h>
    
    int filelist;
    FILE *ptr1, *ptr2, *ptr3;
    float readval=0;
    float dval=0;
    float pval=0;
    
    int first=1;
    char var2[50]="";  /* edited and added thanks Dave I wondered who would be the first to spot that!! ;O) */
    
    int count=0;
    int tot=0;
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    {
     
    	if (	(ptr2=fopen("25_10_v.txt","r")) == NULL) {
    			
    		puts("file2 does not exist");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    	
    	if (	(ptr3=fopen("25_10_add.txt","w")) == NULL) {
    			
    		puts("\nCant open output file");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    
    	
    
    	do {  /* for each line in input file */
    		filelist=fscanf(ptr2,"%[^\n]\n",var2);  
    		if (filelist==-1) break;
    	
    
    					sscanf(&var2[7],"%f",&readval);
    					pval+=readval;
    					sscanf(&var2[28],"%d",&count);
    					tot+=count;
    		}
    	
    	
    			
    	while (  filelist!=-1); /* End of file  */
    
    
    	fprintf(ptr3,"&#163;%9.2f %d\n", pval, tot);
    
    	
    	fclose(ptr2);
    	fclose(ptr3);
    }/*main */
    Last edited by esbo; 10-01-2006 at 09:25 PM.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    I'm surprised it compiled with var2 undeclared.

    [edit]And much of the rest is such a poor example I wouldn't recommend someone new try to emulate it.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Dave_Sinkula
    I'm surprised it compiled with var2 undeclared.

    Sorry I tried to 'tidy it up' a little as it was a bodge from another program, I guess I tieded it up a bit more than I should have

    Here is the original untied version which should compile and work:-

    Code:
    
    #include <stdio.h>
    
    #define TRUE 1
    #define FALSE 0
    #define MINUS -1
    #define POSITIVE 0
    
    int filelist;
    FILE *ptr1, *ptr2, *ptr3;
    float readval=0;
    float dval=0;
    float pval=0;
    char var2[50]="";
    char old_var2[50]="22U";
    int first=1;
    
    int count=0;
    int tot=0;
    
    main(argc,argv)
    	int  argc;
    	char *argv[]; 
    {
     
    	if (	(ptr2=fopen("25_10_v.txt","r")) == NULL) {
    			
    		puts("file2 does not exist");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    	
    	if (	(ptr3=fopen("25_10_add.txt","w")) == NULL) {
    			
    		puts("\nCant open output file");
    		exit(2);	/* an early file does not exist	*/
    	}
    	
    
    	
    
    	do {  /* for each line in dirfile file */
    		filelist=fscanf(ptr2,"%[^\n]\n",var2);  
    		if (filelist==-1) break;
    	
    
    					sscanf(&var2[7],"%f",&readval);
    					pval+=readval;
    					sscanf(&var2[28],"%d",&count);
    					tot+=count;
    		}
    	
    	
    			
    	while (  filelist!=-1); /* End of Directory */
    	fprintf(ptr3,"&#163;%9.2f %d\n", pval, tot);
    
    	
    	fclose(ptr2);
    	fclose(ptr3);
    }/*main */

    Also here is the input file var2, but I think the colum positions mightl be screwed up because this is a simple text file?


    Code:
    U 22U &#163;-6.60     $0.00      63    
    S 32S &#163;-10.63    $0.00      45    
    U 32U &#163;-7.50     $0.00      135   
    U 33U &#163;-11.65    $0.00      58    
    S 42S &#163;-5.30     $0.00      37    
    U 42U &#163;-3.20     $0.00      120   
    S 43S &#163;-6.64     $0.00      33    
    U 43U &#163;-4.30     $0.00      92    
    U 44U &#163;-9.03     $0.00      56    
    S 52S &#163;-5.65     $0.00      41    
    U 52U &#163;-9.00     $0.00      124   
    S 53S &#163;5.30      $0.00      26    
    U 53U &#163;-6.19     $0.00      113   
    S 54S &#163;5.75      $0.00      35    
    U 54U &#163;-1.32     $0.00      115   
    U 55U &#163;-2.25     $0.00      75    
    S 62S &#163;-0.55     $0.00      31    
    U 62U &#163;-7.52     $0.00      134   
    S 63S &#163;-2.90     $0.00      34    
    U 63U &#163;-5.90     $0.00      127   
    S 64S &#163;9.18      $0.00      40    
    U 64U &#163;-4.80     $0.00      118   
    S 65S &#163;8.56      $0.00      43    
    U 65U &#163;-17.15    $0.00      127   
    U 66U &#163;21.55     $0.00      50    
    S 72S &#163;-11.95    $0.00      49    
    U 72U &#163;-7.70     $0.00      111   
    S 73S &#163;0.45      $0.00      33    
    U 73U &#163;-7.25     $0.00      122   
    S 74S &#163;1.65      $0.00      36    
    U 74U &#163;-5.00     $0.00      112   
    S 75S &#163;8.03      $0.00      44    
    U 75U &#163;-15.82    $0.00      133   
    S 76S &#163;-6.50     $0.00      43    
    U 76U &#163;0.72      $0.00      118   
    U 77U &#163;21.38     $0.00      57    
    S 82S &#163;-6.15     $0.00      41    
    U 82U &#163;-4.90     $0.00      117   
    S 83S &#163;-3.90     $0.00      31    
    U 83U &#163;-8.60     $0.00      114   
    S 84S &#163;-7.65     $0.00      43    
    U 84U &#163;-9.75     $0.00      108   
    S 85S &#163;-16.66    $0.00      35    
    U 85U &#163;-6.65     $0.00      119   
    S 86S &#163;-2.40     $0.00      36    
    U 86U &#163;-9.85     $0.00      105   
    S 87S &#163;10.53     $0.00      37    
    U 87U &#163;-21.20    $0.00      109   
    U 88U &#163;-21.89    $0.00      60    
    S 92S &#163;1.00      $0.00      45    
    U 92U &#163;-5.45     $0.00      118   
    S 93S &#163;1.50      $0.00      52    
    U 93U &#163;3.05      $0.00      119   
    S 94S &#163;-1.00     $0.00      29    
    U 94U &#163;-4.90     $0.00      111   
    S 95S &#163;-14.40    $0.00      43    
    U 95U &#163;-7.55     $0.00      106   
    S 96S &#163;-14.20    $0.00      34    
    U 96U &#163;-4.95     $0.00      123   
    S 97S &#163;-2.15     $0.00      38    
    U 97U &#163;-11.90    $0.00      124   
    S 98S &#163;9.65      $0.00      35    
    U 98U &#163;1.25      $0.00      102   
    U 99U &#163;11.69     $0.00      54    
    S A2S &#163;13.52     $0.00      36    
    U A2U &#163;-19.10    $0.00      109   
    S A3S &#163;0.00      $0.00      46    
    U A3U &#163;-8.10     $0.00      124   
    S A4S &#163;23.38     $0.00      37    
    U A4U &#163;-20.80    $0.00      107   
    S A5S &#163;0.40      $0.00      33    
    U A5U &#163;-15.30    $0.00      123   
    S A6S &#163;4.73      $0.00      40    
    U A6U &#163;-20.62    $0.00      117   
    S A7S &#163;17.21     $0.00      41    
    U A7U &#163;-23.65    $0.00      120   
    S A8S &#163;-5.95     $0.00      38    
    U A8U &#163;5.20      $0.00      140   
    S A9S &#163;4.87      $0.00      39    
    U A9U &#163;26.07     $0.00      122   
    U AAU &#163;94.87     $0.00      60    
    S J2S &#163;8.50      $0.00      49    
    U J2U &#163;-4.65     $0.00      128   
    S J3S &#163;-0.90     $0.00      47    
    U J3U &#163;-5.40     $0.00      103   
    S J4S &#163;-9.50     $0.00      34    
    U J4U &#163;-6.10     $0.00      110   
    S J5S &#163;4.15      $0.00      48    
    U J5U &#163;-14.25    $0.00      154   
    S J6S &#163;11.96     $0.00      40    
    U J6U &#163;-7.35     $0.00      123   
    S J7S &#163;-0.24     $0.00      37    
    U J7U &#163;-1.30     $0.00      112   
    S J8S &#163;-3.19     $0.00      43    
    U J8U &#163;4.35      $0.00      130   
    S J9S &#163;32.75     $0.00      49    
    U J9U &#163;-17.20    $0.00      127   
    S JAS &#163;10.28     $0.00      42    
    U JAU &#163;14.47     $0.00      118   
    U JJU &#163;47.70     $0.00      52    
    S K2S &#163;-12.63    $0.00      41    
    U K2U &#163;-9.05     $0.00      126   
    S K3S &#163;-1.25     $0.00      46    
    U K3U &#163;-5.15     $0.00      107   
    S K4S &#163;-3.50     $0.00      27    
    U K4U &#163;-5.00     $0.00      116   
    S K5S &#163;-12.70    $0.00      47    
    U K5U &#163;-5.90     $0.00      117   
    S K6S &#163;5.46      $0.00      27    
    U K6U &#163;-4.75     $0.00      119   
    S K7S &#163;4.00      $0.00      41    
    U K7U &#163;-10.68    $0.00      113   
    S K8S &#163;-9.80     $0.00      38    
    U K8U &#163;-8.70     $0.00      124   
    S K9S &#163;2.10      $0.00      39    
    U K9U &#163;1.47      $0.00      116   
    S KAS &#163;11.98     $0.00      42    
    U KAU &#163;32.74     $0.00      117   
    S KJS &#163;1.38      $0.00      30    
    U KJU &#163;-5.75     $0.00      122   
    U KKU &#163;43.63     $0.00      54    
    S Q2S &#163;1.86      $0.00      35    
    U Q2U &#163;-9.05     $0.00      127   
    S Q3S &#163;0.79      $0.00      35    
    U Q3U &#163;-7.55     $0.00      116   
    S Q4S &#163;5.90      $0.00      24    
    U Q4U &#163;-5.15     $0.00      93    
    S Q5S &#163;10.70     $0.00      38    
    U Q5U &#163;-13.45    $0.00      127   
    S Q6S &#163;-1.50     $0.00      35    
    U Q6U &#163;-9.00     $0.00      107   
    S Q7S &#163;-10.15    $0.00      43    
    U Q7U &#163;15.10     $0.00      123   
    S Q8S &#163;-14.10    $0.00      42    
    U Q8U &#163;-11.35    $0.00      126   
    S Q9S &#163;-1.75     $0.00      40    
    U Q9U &#163;-6.60     $0.00      115   
    S QAS &#163;-30.45    $0.00      29    
    U QAU &#163;44.71     $0.00      126   
    S QJS &#163;12.82     $0.00      35    
    U QJU &#163;-6.63     $0.00      132   
    S QKS &#163;2.20      $0.00      44    
    U QKU &#163;15.07     $0.00      125   
    U QQU &#163;59.03     $0.00      56    
    S T2S &#163;7.65      $0.00      43    
    U T2U &#163;-3.05     $0.00      122   
    S T3S &#163;2.65      $0.00      34    
    U T3U &#163;-3.70     $0.00      101   
    S T4S &#163;1.77      $0.00      34    
    U T4U &#163;-8.90     $0.00      97    
    S T5S &#163;0.75      $0.00      39    
    U T5U &#163;-10.45    $0.00      114   
    S T6S &#163;3.87      $0.00      43    
    U T6U &#163;0.45      $0.00      134   
    S T7S &#163;1.70      $0.00      48    
    U T7U &#163;1.57      $0.00      110   
    S T8S &#163;1.40      $0.00      51    
    U T8U &#163;-6.86     $0.00      114   
    S T9S &#163;17.18     $0.00      48    
    U T9U &#163;-5.35     $0.00      127   
    S TAS &#163;12.72     $0.00      49    
    U TAU &#163;-0.09     $0.00      114   
    S TJS &#163;-1.21     $0.00      30    
    U TJU &#163;-11.87    $0.00      110   
    S TKS &#163;13.17     $0.00      41    
    U TKU &#163;24.21     $0.00      121   
    S TQS &#163;20.20     $0.00      47    
    U TQU &#163;-25.40    $0.00      101
    If it works it should produce the output.:-
    Code:
    &#163;   -24.59 12950

    Which means I have lost &#163;24.59 playing poker ( on a &#163;0.25/&#163;0.50 ten player poker tables)
    (it shows how much I win/lose for particular starting cards (S=suited U=unsuited) in 12,950 games
    However I also play games with less than 10 payers and at higher stakes than &#163;0.25/&#163;0.50
    (up to &#163;5/&#163;10 on occasion), which are not included. If I included these it would show me several hundred pounds up

    I suspected I lost at these lower level, 'full table' games, and now I have proved it!! I seem to better with less players and at higher stakes

    Note I do best when I hold a pair of Aces, as you might expect!!
    U AAU &#163;94.87 $0.00 60

    Dunno why I so worse at the low level big games, I think I am looser with my money and get bored waiting for my turn to play so I over play my cards, and play too many hands to relieve the boredom!!

    The second column is the number of hands I was dealt of that particular combination.


    What surprised me is how much I lost with Ace Queen suited (thats a very good starting hand and you would expect to see a value of about +&#163;10 or more:-
    S QAS &#163;-30.45 $0.00 29

    Investigating that at the moment
    Last edited by esbo; 10-01-2006 at 09:40 PM.

  8. #8
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Dave_Sinkula
    I'm surprised it compiled with var2 undeclared.

    [edit]And much of the rest is such a poor example I wouldn't recommend someone new try to emulate it.

    Fair comment, but it should work now I have amended the deliberate error
    I just thought I would post a quick example of file I/O which worked, I tried to 'tidy up'
    some of my bad programming style, but unfortunately it's usually best to 'leave well alone',
    a compiler will often forgive 'bad style' but it usually won't forgive the slightest editiing error!!

  9. #9
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Just though I would add that I do far better with Ace Queen unsuited (a poorer hand!!)
    U QAU &#163;44.71 $0.00 126

    Strange game poker!!

    By the way my loses from that file work out at 0.2 pence per hand, hardly a fortune!! (Takes 500 hands to lose &#163;1, cheap entertainment anyway)
    At that level a good player could expect to win 50p-75p per hundred hands. (unless they were playing other good players), futher more on an average pot of &#163;3 with a rake of 5% 15 pence goes to the 'banker'
    each hand which is 1.5p per player on average, which makes my 0.2p
    look quite good!! (7.5 times better than your average player anyway, if my maths is correct!!)
    Last edited by esbo; 10-01-2006 at 10:02 PM.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Just shut up! This thread isn't about poker! No one cares how much you lose. Stop crapping up people's threads.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > main(argc,argv)
    > int argc;
    > char *argv[];
    Get with the times and use ANSI-C
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    Wow... I wonder why the topic suddenly changed...

    Well, back to the topic... Okay, now I understand a little of my program but now I have another DIFFERENT FILE problem..

    My program isn't saving the user's input, why's that?

    Here is my code... It's very long.. I don't know which part is wrong about it. I triple checked it but I can't figure out what's wrong.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <conio.h>
    
    struct qpi
    {
           int studid;
           char name[100];
           char sub[2];
           char totqpi[2];
           char rank[8];
           char totunit[2];
    };
    
    
    void new_stud(void);
    void view_stud(FILE *);
    
    int main()
    {
        char choose1;
    
    intro1:
        
        printf("ACADEMIC HONORS COMPUTATION");
        printf("\n\n");
        {
           FILE *open;
           if ((open = fopen("fileqpi.txt", "r")) != NULL)
               printf("\n");
           else
           {
               printf("The file \"fileqpi.txt\" cannot be opened\n");
               printf("It is either the file does not exist or there is something");
               printf("\nwrong with the file");
           }
           fclose(open);
        }
    
           printf("\tCompute a student's QPI........c\n");
           printf("\tView the list..................v\n");
           printf("\tLeave..........................l\n");
           printf("\tEnter the letter of your choice: ");
           scanf("%c", &choose1);
           fflush(stdin);
           if (choose1 == 'c')
           new_stud();
           else if(choose1 == 'v')
           {
                printf("Viewing database...\n");
                {
                   FILE *open;
                   if ((open=fopen("fileqpi.txt", "r")) != NULL)
                            printf("\n");
                   else
                   {
                       printf("The file \"fileqpi.txt\" cannot be opened\n");
                       printf("It is either the file does not exist or there is something");
                       printf("\nwrong with the file");
                   }
                   view_stud(open);
                   fclose(open);
                }
           }
           else if (choose1 == 'l' )
    	   {
    		    system("cls");
    		    exit(1);
           }
          else if((choose1 != 'a') || (choose1 != 'l') || (choose1 != 'v'))
               {
                 printf("Error! The letter you inputted is not part of the choices");
                 printf("Please restart the program if you want to continue");
               }
          goto intro1;
    }
    
    void new_stud(void)
    {
         FILE *fileqpi;
         
         int sub2, i;
         float grde, unit, tot, mult, sum, qou;
         
         struct qpi file={ 0, "", "", "", "", "" };
         system("cls");
         if ((fileqpi = fopen( "fileqpi.txt", "r+" ) ) == NULL )
    	{
    		printf( "Error! Something happened while accessing the file\n" );
    		main();
    	}
        else
        {
            
            printf("\t\tNOTICE:\nBefore starting, ");
            printf("\nmake sure there is no INC in any of the student's subjects.\n\n");
            printf("Enter student's ID number (To quit, type 0): ");
            scanf("%d", &file.studid);
            fflush(stdin);
            while(file.studid != 0)
            {
                 printf("Starting QPI computation...\n Enter number of subjects: ");
                 scanf("%d", &sub2);
                 for(i=0; i<sub2; ++i)
                 {
                    printf("Grade of Subject %d: ", i+1);
                    scanf("%f", &grde);
                    printf("Number of Units for Subject %d: ", i+1);
                    scanf("%f", &unit);
                    mult = grde*unit;
                    sum += mult;
                 }
                 printf("Input total number of units: ");
                 scanf("%f", &tot);
                 qou = sum/tot;
                 printf("QPI is %.2f", qou);
                 if((qou>=3.70) && (qou<=4.00))
                       printf("\nStudent is qualified for First Honors");
                 else if((qou>=3.25) && (qou<3.70))
                       printf("\nStudent is qualified for Second Honors");
                 else
                       printf("\nStudent is not qualified to be an Honor");
                 printf("\n\nSaving to files...\n");
                 printf("Enter complete name of student:\n");
                 fscanf(stdin, "%s", file.name);
                 fflush(stdin);
                 printf("Enter total number of subjects:\n");
                 fscanf(stdin, "%s", file.sub);
                 fflush(stdin);
                 printf("Enter total number of units:\n");
                 fscanf(stdin, "%s", file.totunit);
                 fflush(stdin);
                 printf("Enter QPI of student:\n");
                 fscanf(stdin, "%s", file.totqpi);
                 fflush(stdin);
                 printf("Enter rank of student:\n");
                 fscanf(stdin, "%s", file.rank);
                 fflush(stdin);
    			 fseek(fileqpi, (file.studid-1) * sizeof(struct qpi), SEEK_SET );            
                 system("cls");
                 printf("Enter Enter student's ID number (To quit, type 0): ");
                 scanf("%d", &file.studid);
                 fflush(stdin);
             }
             fclose(fileqpi);
        }
        system("cls");
    }
    
    void view_stud(FILE *fileqpi)
    {
         FILE *viewtext;
         struct qpi file = {0, "", "", "", "", ""};
         system("cls");
         if((viewtext = fopen("fileqpi.txt", "w"))==NULL)
         {
             printf("Error! Something happened while accessing the file");
             fclose(viewtext);
             main();
         }
         else
         {
             rewind(fileqpi);
             fprintf(viewtext, "%-11s%-22s%-22s%-15s%-20s%-20s%\n", "ID No.", "Name", "No. of Subjects", "No. of Units", "QPI Average", "Rank");
             while ( !feof( fileqpi ) )
    		{
    			fread( &file, sizeof( struct qpi ), 1, fileqpi );
    			if (file.studid != 0)
    			fprintf(viewtext, "%-11d%-22s%-22s%-15s%-20s%-20s%\n", file.studid, file.name, file.sub, file.totunit, file.totqpi, file.rank);
    		}
    		fclose(viewtext);
    	}
    	printf( "Creating database.txt file for viewing.....\n" );
    	system( "notepad fileqpi.txt" );
    	system( "cls" );
    }
    If you want to run it, make sure that there is a file named "fileqpi.txt" already saved in your documents or else it won't run normally... Thanks for helping (if someone will help. )

    TO ALL THOSE WITH FRIENDSTER, ADD ME!

    i'm [email protected]
    a newbie in the field of Computer Science!! Pray for all the student's success!

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1 - Learn to use loops instead of goto all the time.
    2 - Don't ever call main. Return back to it, and user your loop.
    3 - Stop using fflush( stdin ), it's wrong.
    4 - system is not really something you should be using.
    5 - feof really shouldn't be used to control loops.
    6 - Never ever listen to esbo. He's an idiot.

    I'm sure there's more, but that's what we're dealing with at a glance. I would suggest pretty much scrapping your whole program and starting over. Learn how to use a loop instead of goto, and to call functions which return useful information back to your loop or loop control.


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Please tell me you aren't using goto!

  15. #15
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    Why? What's wrong with goto? For me, goto is simplier than making loops... Eh... How can I make a loop from that? And my original problem is about saving files, what's that got to do with solving my problem? :cry:

    HOW CAN I SAVE THE USER'S INPUT IN THE QPI.TXT FILE??? HUHUH...

    TO ALL THOSE WITH FRIENDSTER, ADD ME!

    i'm [email protected]
    a newbie in the field of Computer Science!! Pray for all the student's success!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string methods hard time
    By Micko in forum C++ Programming
    Replies: 2
    Last Post: 08-07-2006, 10:00 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  5. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM