is random access possible on struct records in C language?
Sushma21
0
Newbie Poster
Recommended Answers
Jump to PostI guess, you are looking for Random Access IO. Take a look at http://c-faq.com/~scs/cclass/int/sx2i.html.
Jump to Postwhat do u mean by that ?
If u want to randomly access some struct records u can make an array of that struct and proceed........
Jump to Postya...i tried doing that....i accepted array of records in 1 program and tried to access it randomly in other program by opening the file in read mode and using fseek and fread functions....but it is showing some garbage values....so i have a doubt if we can acess struct records randomly …
Jump to Postthis is the program where i input struct records...
#include<stdio.h> #include<conio.h> struct Product {
end quote.
post your program properly.
Jump to Post1> u are doing
fwrite(p,(size*sizeof(p)),size,fp);
which tries to write the whole things together. Better try the following in the file for writting
for(i=0;i<size;i++) { p[i]=read_rec(); fwrite(&p[i], sizeof(product), 1, fp); }
and hence u wont need the p[] array u can do
All 22 Replies
kvprajapati
1,826
Posting Genius
Team Colleague
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
kvprajapati
1,826
Posting Genius
Team Colleague
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Sushma21
0
Newbie Poster
dkalita
110
Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.