473,386 Members | 2,050 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,386 software developers and data experts.

error while using file i/o operation in ansi c

i have a file as STUDENT.TXT, i have to do a file manipulation function in this progarmme,, i can't do all the manipulation in this programme,, what is the wrong ?


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. struct student
  6. {
  7. int rno;
  8. char name[25];
  9. int m1,m2;
  10. }s1;
  11.  
  12. void main()
  13. {
  14. int ch, n;
  15.  
  16. FILE *fp1,*fp2;
  17.  
  18. do 
  19. {
  20. clrscr();
  21. printf("\n 1.insertation");
  22. printf("\n 2.Deletion");
  23. printf("\n 3.modification");
  24. printf("\n 4.View");
  25. printf("\n 5.exit");
  26.  
  27. printf("\n Enter Your Choice:-\n");
  28. scanf("%d",&ch);
  29.  
  30.  
  31. switch(ch) 
  32. {
  33. case 1:
  34. fp1=fopen("STUDENT.TXT","a+");
  35. printf("\nEnter The Roll no:-\n ");
  36. scanf("%d",&s1.rno);
  37. printf("\nEnter The Name:-\n ");
  38. scanf("%s",s1.name);
  39. printf("\nEnter The m1:-\n ");
  40. scanf("%d",&s1.m1);
  41. printf("\nEnter The m2:-\n ");
  42. scanf("%d",&s1.m2);
  43.  
  44. fprintf(fp1,"\nRoll no:-%d\n ",s1.rno);
  45. fprintf(fp1,"\nName:-%s\n ",s1.name);
  46. fprintf(fp1,"\nm1:-%d\n ",s1.m1);
  47. fprintf(fp1,"\nm2:-%d\n ",s1.m2);
  48.  
  49. fclose(fp1);
  50. printf("\n Record is successfully Added");
  51. getch();
  52. break;
  53.  
  54. case 2:
  55. printf("Enter the roll no to be deleted\n");
  56. scanf("%d",&n);
  57. fp1=fopen("STUDENT.TXT","r");
  58. fp2=fopen("DDD.TXT","w");
  59.  
  60. while(!feof(fp1))
  61. {
  62. fscanf(fp1,"%d",&s1.rno);
  63. fscanf(fp1,"%s",s1.name);
  64. fscanf(fp1,"%d",&s1.m1);
  65. fscanf(fp1,"%d",&s1.m2);
  66.  
  67. if (s1.rno!=n)
  68. {
  69. fprintf(fp2,"\nRoll no:-%d\n ",s1.rno);
  70. fprintf(fp2,"\nName:-%s\n ",s1.name);
  71. fprintf(fp2,"\nm1:-%d\n ",s1.m1);
  72. fprintf(fp2,"\nm2:-%d\n ",s1.m2);
  73. }
  74. }
  75. printf("This record is deleted!!");
  76. fclose(fp1);
  77. fclose(fp2);
  78. remove("STUDENT.TXT");
  79. getch();
  80. break;
  81.  
  82.  
  83. case 3:
  84. printf("Enter the roll no to modification\n");
  85. scanf("%d",&n);
  86. fp1=fopen("STUDENT.TXT","r");
  87. fp2=fopen("DDD.TXT","w");
  88.  
  89. while(!feof(fp1))
  90. {
  91. fscanf(fp1,"%d",&s1.rno);
  92. fscanf(fp1,"%s",s1.name);
  93. fscanf(fp1,"%d",&s1.m1);
  94. fscanf(fp1,"%d",&s1.m2);
  95.  
  96. if (s1.rno!=n)
  97. {
  98. fprintf(fp2,"\nRoll no:-%d\n ",s1.rno);
  99. fprintf(fp2,"\nName:-%s\n ",s1.name);
  100. fprintf(fp2,"\nm1:-%d\n ",s1.m1);
  101. fprintf(fp2,"\nm2:-%d\n ",s1.m2);
  102. }
  103. else
  104. {
  105. printf("\n Old data Are:-\n");
  106. printf("%d\n%s\n%d\n%d\n",s1.rno,s1.name,s1.m1,s1.m2);
  107. printf("Enter the new data \n");
  108. printf("\nEnter The Roll no:-\n ");
  109. scanf("%d",&s1.rno);
  110. printf("\nEnter The Name:-\n ");
  111. scanf("%s",s1.name);
  112. printf("\nEnter The m1:-\n ");
  113. scanf("%d",&s1.m1);
  114. printf("\nEnter The m2:-\n ");
  115. scanf("%d",&s1.m2);
  116.  
  117.  
  118. fprintf(fp2,"\nRoll no:-%d\n ",s1.rno);
  119. fprintf(fp2,"\nName:-%s\n ",s1.name);
  120. fprintf(fp2,"\nm1:-%d\n ",s1.m1);
  121. fprintf(fp2,"\nm2:-%d\n ",s1.m2);}
  122. }
  123. printf("\nthis record is updated");
  124. fclose(fp1);
  125. fclose(fp2);
  126. remove("STUDENT.TXT");
  127. rename("DDD.TXT","STUDENT.TXT");
  128. getch();
  129. break;
  130.  
  131.  
  132. case 4:
  133. fp1=fopen("STUDENT.TXT","r");
  134. while(!feof(fp1))
  135. {
  136. fscanf(fp1,"%d",&s1.rno);
  137. fscanf(fp1,"%s",s1.name);
  138. fscanf(fp1,"%d",&s1.m1);
  139. fscanf(fp1,"%d",&s1.m2);
  140.  
  141. printf("\nRoll no:- %d\n ",s1.rno);
  142. printf("\nName:- %s \n ",s1.name);
  143. printf("\nm1:- %d\n ",s1.m1);
  144. printf("\nm2:- %d\n ",s1.m2);
  145. }
  146. fclose(fp1);
  147. getch();
  148. break;
  149.  
  150. case 5:
  151. exit(0);
  152. break;
  153.  
  154. }
  155. }
  156. while(ch!=5);
  157. getch();
  158. }
Oct 12 '12 #1
1 1874
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

You're the one that has to tell us what's wrong. Are you getting error messages? What are they? Is it running but not doing what you want? What is it doing wrong? What is it supposed to do?

Only you know the answers to those questions. And we need those answered before we can figure out how to fix what's wrong. But first you have to tell us.
Oct 12 '12 #2

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

Similar topics

0
by: Mark Depenbrock | last post by:
--Apple-Mail-2--68472726 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Can not make mysql connection - error log: 030708 08:53:48 mysqld started
3
by: sjoshi | last post by:
I'm doig a test using XP English with LocalSettings set to Russian. When trying to open an XML file with ANSI encoding, I get errors. When I change the encoding to UTF8, I can read the file...
0
by: | last post by:
Hi, I am using VS2003 .NET. I have a union in my files which is generated by YACC. I am getting the following errors while linking using link.exe(Microsoft (R) Incremental Linker Version...
1
by: Laurent Lequenne | last post by:
Hello There, I just converted a VS 2003 C++ Project into VS 2005. I already made some changes in my headers files, has I had compilations errors with enums declarations. Now everything compiles...
2
by: Jay | last post by:
Hi, This is Jay Mehta. I have this problem when using LDAP. I extract names and EmailId's of all those present from LDAP and populate in a datagrid. Now when run locally, it is running...
1
by: vchezel | last post by:
Hi, I did a project in c++ to do file operations.The output of the program would be like this File create\File1_1 created File create\File1_1 Copied to copy\FileDest_1 File copy\FileDest_1 (6302...
0
by: tekiegreg | last post by:
Hi there, here is a snippet of my code that I've been getting an error message on, basically what I've been trying to do is pull out appointments, serialize to an object as well as all the contacts...
5
by: Sonasang | last post by:
Hi , I am creating a web page with ASP and Javascript.We have shared the foldres containg the code and all our team members are accessing the code. There is no problem for me when i run the...
21
by: raagadeepthi | last post by:
Getting invalid file operation when using the below code. Iam running this on client machine and have created one director by name 'DEEPS' and have given read/write privileges ran the below quries...
2
by: Jayesh Patel | last post by:
I am trying to run below query in vb6 but i found runtime error like"Syntax error in Join Operation (Runtime Error)" Please help. Query: SELECT Sum(Ageing_Master.DAYS_0_30) AS SumOfDAYS_0_30 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.