473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why Does it Write Only Once to File And Never Again

I am working on a project( almost finished) but this last part is ridiculously killing me Here is the code I have:

Expand|Select|Wrap|Line Numbers
  1. Ca_Info rpd[data];
  2.     int i=0, choice, transnum,regch,ret=0;
  3.     trans ruc;
  4.     Ca_Info rting;
  5.     FILE *rfp,*verfp;
  6.     char stat[]="available";
  7.  
  8.     rfp=File_Handler(rent,App_Read);
  9.     verfp=File_Handler(veh,Read_B);
  10.     FindByStat(stat,rpd);
  11.     printf("\t\t\tAvialable List\n");
  12.         while(1)
  13.         {
  14.             if ((strcmp(rpd[i].status,stat)!=0) &&(i==0))
  15.             {
  16.                 printf("No Cars to rent\n");
  17.                 system("pause");
  18.                 return;
  19.             }
  20.             if(strcmp(rpd[i].status,stat)!=0)
  21.             {
  22.                 break;
  23.             }
  24.             printf("-----------------------\t-----------------------\t-----------------------\t\n");
  25.             printf("-----------------------\t|         %d          |\t-----------------------\t\n",i+1);
  26.             printf("-----------------------\t-----------------------\t-----------------------\t\n");
  27.             printf("Reg.No:%d   Year:%d   2:No.of Seats:%d  3:Type:%s    4:Model:%s\n5:Colour:%s   6:Status:%s   7:Rent Rate:%.2f   8:Insurance Rate:%.2f\n",rpd[i].regnum,rpd[i].year,rpd[i].no_Seats,rpd[i].type,rpd[i].model,rpd[i].col,rpd[i].status,rpd[i].rent_Rte,rpd[i].irancRte);
  28.             printf("-----------------------\t-----------------------\t-----------------------\t\n");
  29.             i++;
  30.         }
  31.     printf("Enter Number choice for car\n");
  32.     scanf("%d",&choice);
  33.     memcpy(&rting,&rpd[choice-1],sizeof(rpd[choice-1]));
  34.     system("cls");
  35.     printf("Enter date\n");
  36.     scanf("%d %s %d %s %d",&ruc.dte.DD,&ruc.dte.sls,&ruc.dte.MM,&ruc.dte.sls1,&ruc.dte.YY);
  37.     printf("Enter customer full name(Use - for spaces)\n");
  38.     scanf("%s",ruc.c_Nme);
  39.     printf("Enter driver's License #\n");
  40.     scanf("%d",&ruc.d_Lic);
  41.     printf("Enter address(Use - for spaces)\n");
  42.     scanf("%s",ruc.addr);
  43.     printf("Enter name of a sponsor(Use - for spaces)\n");
  44.     scanf("%s",ruc.spon_Nme);
  45.     printf("Enter duration of rental in days\n");
  46.     scanf("%d",&ruc.time);
  47.     printf("Enter credit card number\n");
  48.     scanf("%s",ruc.cre_Crd);
  49.     printf("Enter name on credit card(Use - for spaces)\n");
  50.     scanf("%s",ruc.crd_Own);
  51.     ruc.ins_Cost= rting.irancRte * ruc.time;
  52.     ruc.rnt_Cost= (rting.rent_Rte * ruc.time)+ruc.ins_Cost;
  53.  
  54.             while(1)
  55.             {
  56.                 Random(ruc.transnum,6);
  57.                 ret = FindInfo(rfp,NULL,atoi(ruc.transnum),0);
  58.                     if (!ret)
  59.                     {
  60.                         continue;
  61.                     }
  62.                     else
  63.                     {
  64.                         break;
  65.                     }
  66.             }
  67.             strcpy(rting.status,"Out");
  68.             fflush(rfp);
  69.             fprintf(rfp,"%s\t%d\t%d\t%s\t%d%s%d%s%d\t%d\t%.2f\t%.2f\t%s\t%s\n",ruc.transnum,rting.regnum,ruc.d_Lic,ruc.c_Nme,ruc.dte.DD,ruc.dte.sls,ruc.dte.MM,ruc.dte.sls1,ruc.dte.YY,ruc.time,ruc.ins_Cost,ruc.rnt_Cost,ruc.cre_Crd,rting.status);
  70.             regch=rting.regnum;
  71.             Update(regch);
  72.             fclose(rfp);
  73.             fclose(verfp);
  74. }
Jul 29 '14 #1
2 1191
weaknessforcats
9,208 Expert Mod 8TB
I have no idea.

There is only one fprintf at the end of your posted code so you would write once.

However, I can't tell what's happening from the code snippet that was posted. The code is part of some function and it would help to see the entire function.
Jul 29 '14 #2
donbock
2,426 Expert 2GB
Line 8 uses File_Handler to presumably open file rfp.
Line 57 uses FindInfo to do something with file rfp.
Line 68 flushes file rfp.
Line 69 prints one line to file rfp.
Line 72 closes file rfp.

Are you opening file rfp for read, write, or append? Do you select update mode? Refer to description of the fopen mode argument.
Jul 29 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Google Mike | last post by:
I have PHP version 4.2.2 that ships with RH9. I want to have it write to a file like this: function WriteLog($sLogFile, $sMsg) { if (substr($sLogFile,1,1) != '/') { $sLogFile =...
6
by: Tony C | last post by:
Does Python have a function that is analogous to C's write() or fwrite()- that is , I want to write a file (of arbitrary data) that is 100K, or 1MB (or more) bytes long.. Both write() and...
6
by: rxl124 | last post by:
someone please please help w/ this one. As I been working on this on and off and it just does not want to work. 1 #!/usr/bin/perl -w 2 3 $file = "/home/user1/dothis"; 4 open(FILE, ">$file");...
1
by: Jim Heimer | last post by:
Hi, I've been using schema.ini to read an ascii file to a dataset. Would it be possible to write to the ascii file the same way I read from it? In my case, the initial ascii file has two...
2
by: ykgoh | last post by:
Hi. I've a problem of being able to create and remove a directory but unable to write a file inside the created directory for some strange reason. I suspect that this problem could be vaguely...
1
by: Daniel | last post by:
does the windows file handle change? are file handles unique to the whole operating system or just the current directoy? if a file is opened then closed then opened again, does the file handle...
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
6
by: ericunfuk | last post by:
Hi ALL, I want to read a binary file(it's pic.tif file, I guess it's binary file?), then write it to a new file), I have several questions about this process: When I use fread() to read a...
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
0
by: geradmcginty | last post by:
Forgive me in advance, but I have a word.dot that inserts a unique receipt number sequentially into the header of the document on open, trouble is when ever someone else opens the doc it runs again...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.