473,490 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write structure record into file using fwrite() function?

40 New Member
1.i am just trying to insert a "structure record" into a file using fwrite() function by the following code

2.
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int rollno;
};
void main()
{
FILE *fp1;
struct student s1={"",0};
clrscr();
printf("enter the details\n");
scanf("%s %d",s1.name,&s1.rollno);
printf("%d\n",s1.rollno);
fp1=fopen("empdet.txt","w");
fwrite( &s1,sizeof( struct student ),1,fp1 );
printf("the record is entered");
fclose(fp1);
getch();

}

3.when i executed the above program,it just inserting only the "name" field and
the "rollno" field with some garbage

4.please,someone help me....
Jun 26 '08 #1
2 11431
weaknessforcats
9,208 Recognized Expert Moderator Expert
The rollno member of the struct is an int but the file is a text file.

Convert the int to a string and write the string.

Or open the file as a binary file but don't expect to view the contents with a text editor.
Jun 26 '08 #2
shivapadma
40 New Member
yes,i have converted the rollno(int) into string

now i am able to insert both name and rollno.

thanks....
Jun 26 '08 #3

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

Similar topics

5
8262
by: Paolo | last post by:
Friends, I have created a form with a list box that shows all my Word files. I have then added the following code (found on comp.databases newsgroup) to the Open event of my form and it works...
1
1958
by: novadoft | last post by:
var textTobeWritten = blah(); var fso = new ActiveXObject("Scripting.FileSystemObject"); var tempFile = fso.OpenTextFile(originalFilename, 2, true); tempFile.Write(textTobeWritten);...
1
5876
by: stuart.medlin | last post by:
I have an Access 2003 application that I recently converted from Access 97. I have a routine in which I use to export the data that the users have keyed into a text file. This text file resides...
0
1121
by: duclm | last post by:
Hi all, II am having problem sending zip file(binary file) using webrequest function from wince5.0 device to a webpage. It works fine for any file with size less than or equal to 1.5kb. Any bigger...
0
1235
by: newUser1234 | last post by:
I'm trying to read and write from an excel file using this method..My application can read the excel file without problems but doesn't write anything to the file i want it to write. I've also tried...
3
1730
by: neehakale | last post by:
can ny body tel me how to write a data from form say, Name and Age to excel file...
3
7056
BishoMicho
by: BishoMicho | last post by:
What i want to do is to implement visitor counter in the home page of a web application, with daily visitors and total visitors. i don't want to use code behind, i want to use javascript to write...
7
2982
by: chazzy69 | last post by:
Ok basically i need to figure out why i cant pass a variable as a parmater in the fwrite function. heres the code that does NOT work - $output = "hello world"; //note not the actual string...
1
2215
by: Arulmanoj | last post by:
Hi, I have to write the content from one csv file to another csv file using VB Script. The scource content file contains 5 columns and the destination file contains six column as below. Source...
0
7112
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
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
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,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.