I have a text file I use to hold an index of files and words (with their frequencies) that appear in them. I need to read the file into memory and ... |
James Fang wrote: I need to edit a random position of a file, for e.g, the 500th byte. To keep portability, I would like to use standard C++ instead of os apis. Could you help on this? What exactly do you need help with? Open the file for read+write. Position the stream at 500. Write the new byte. Close the stream. ... |
1) Don't be sprouting threads all over the place... 2) Don't be demanding code. I gave you a good example as a starting point... now it's up to you to apply brain to task and *figure this out on your own*, with a little help when you get stuck. We are here to help people debug their code, offer occasional suggestions ... |
Random Access Files...ugh. This is a program I wrote a few weeks ago for an online class, but it won't execute properly, and I've been trying to fix it for awhile now. The compiler doesn't give any build errors, but it will allow the user to create a tool record, but then a few problem come up... I want to try ... |
I have the following code to randomly seek inside a file and read (or write) that location. When I try to execute it for a 32 mb (1<<25) file using: ./a.out /dev/sda3 25, it gives the error: Error in read : Invalid argument. Whats wrong and how do I fix it? Code: #define _GNU_SOURCE #include #include #include #include ... |
|
Random access files and structures Right now I'm trying to read in a buncho f data from the text file "Top_Movies.txt" and putting the data into a structure. This is what I have so far. Now I know it isn't goign to work so I'm not even going to bother trying to compile it...but am I even close? I think I ... |
|
Hey guys. I need some help..bad. I have to write a program that creates a file of randomly distributed numbers. I have the functions figured out and some of the main(). Could you guys take a look at it and just try to steer me in the right direction. I'm just confused on how to get a filename from user, and ... |
#include #include #include #include #include #include void main(void) { char **line,c; int i=0,j=0,*slen,a,k; FILE *myfile; myfile = fopen("mycookies.txt","r"); if (myfile == NULL) { printg("Warning!Cannot open file."); exit -1; } while ( !feof(myfile) ) { fscanf(myfile,"%c",c); while(c!='\n') { line[i][j]=c; fscanf(myfile,"%c",&c); j++; } slen[i]=j; i++ } a=randomize(i); for(k=0;k |
Hi!! I am a newbie at C programming, and I need help wih my program... I am suppose to write a C program that opens up the generated file and produces a report that looks like: Number of records : you determine the value and print it here Maximum Value : you determine the value and print it here Minimum Value ... |
|
Code: #include /*********** Data ***********/ typedef struct { int id; float gpa; }data; /*********** The functions ***********/ void read(data*); void print(FILE*); /*********** Main ***********/ int main(){ data R; FILE *f; int i; if((f=fopen("f.dat","w"))==NULL) printf("sorry i can not open the file\n"); else{ fseek(f,sizeof(data),SEEK_SET); for(i=1;i<=3;i++){ read(&R); fseek(f,sizeof(data)*(i-1),SEEK_SET); fwrite(&R,sizeof(data),1,f); } } print(f); return 0; } /*********** Read ***********/ void read(data *R){ printf("Enter the id ... |
When I tried your code, it produced the same output. It worked the first time. So I tried to input new data and it produced the same semi-gibberish output the second time around. Don't worry about that, the fseek seems to work ok. What I'm now having trouble with is the reorder field of the structure. It keeps changing the integer ... |
I'm in the process of creating a program that maintains a staff details file. I've got all the code that creates a random access file, and I can add entries and sort them in the right order within the file. I have now hit a brick wall when it comes to modifying an existing record within the file. The file contains ... |
I have the following code to randomly seek inside a file and read (or write) that location. When I try to execute it for a 32 mb (1<<25) file using: ./a.out /dev/sda3 25, it gives the error: Error in read : Invalid argument. Whats wrong and how do I fix it? Code: #define _GNU_SOURCE #include #include #include #include ... |
Hi guys, I've searched on these forums for info that I hoped would help me to 'get it' in terms of what it is I'm trying to do, but so far I've just got more and more bogged down with confusion, so I hope you can help me. I'm writing a program in C (which I'm fairly new to) where I ... |
Just a quicky, Is it possible to do random access file reads using C [not C++]. I would like to say somthing that would conform to :- get me the characters from file Ptr, starting at possition X, and ending att possition Y. I know that it probally seems a tedious thing to ask but searchin both google and here have ... |
void addReserve() { char uoption; int option=0; int i=0; int count = 1; int res_num; FILE *reserver; srand(time(NULL)); if((reserver=fopen("reservations.txt", "rb+"))==NULL) { printf("\nFile could not be opened, file is now be created"); if((reserver=fopen("reservations.txt", "wb+"))==NULL) { printf("Error in creatiing/opening file"); _getch(); } else { for (; i < 100; i++) { fwrite( §ion, sizeof( ADMISSION_DATA ), 1, reserver ); printf("\nRecord # %d", count); ... |