473,320 Members | 1,957 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,320 software developers and data experts.

I/O help...I think,,,

3
This part of C always gets me...it shouldn't...but it does, so here I go:
I've looked everywhere but I can't find the answer anwhere

void Arrays (int numArray[], int quantity[])

{
FILE *fp;
fp = fopen("stock.dat", "rb+");
fclose(fp);
}

if I wanted to put the data from the file into the two arrays how would I go about doing this? I can only find the explanations of to read in one..how would I go about reading the record layout in?
Aug 6 '07 #1
6 1389
weaknessforcats
9,208 Expert Mod 8TB
This code:
void Arrays (int numArray[], int quantity[])

{
FILE *fp;
fp = fopen("stock.dat", "rb+");
fclose(fp);
}
will be hard for you to use. That is, when you pass an array to a function, all that is passed is the address of element 0. So here you have two int pointers for your two arrays but you do not have the number of elements in these arrays.

You need to tell fread how much to read.
Aug 7 '07 #3
cap213
3
I think I'm figuring it out...if I wanted to scan the first half of the line, which is set up 348247:title. How would I accomplish this...I've tried this...but it does not seem to be working...(the title which it is comparing to is passed from another fucntion..)

int search(char title[81], int *stocknum[])
{
int j;
char tite[81];
FILE *va;
va = fopen("/Users/cap412/Desktop/videos.dat", "r");
for (j = 0; j < 50; j++){
fscanf(va, "%s", tite[j]);
if(strncmp(tite, title, 81) == 0)
fscanf(va, "%[0-9]", &stocknum[j]);
fclose(va);
}
}
Aug 10 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
The first thing is to stop using fscanf(). This thing skips whitespace.

Use fread() and read in the correct number of bytes or use fgets() which will read in an entire line of text, which you can then parse.
Aug 10 '07 #5
cap213
3
The first thing is to stop using fscanf(). This thing skips whitespace.

Use fread() and read in the correct number of bytes or use fgets() which will read in an entire line of text, which you can then parse.
okay, so it can read in, only, the line where the text is located?
Aug 10 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
I assume you know the file format. Yes?

Let's assume the file format is two arrays of 10 ints each.

Expand|Select|Wrap|Line Numbers
  1. int readbuffer[20]
  2.  
  3. fread(readbuffer, 20 * sizeof(int), 1, myfile);
  4.  
Then just distribute the readbuffer array to your two arrays. You know that the first array is readbuffer[0] through readbuffer[9], etc.

I'm just guessing here as I don't know your file format.
Aug 11 '07 #7

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

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
4
by: Mike | last post by:
Hello All, I'm trying to deploy my windows-based application using crystal report. i package the setup by including the crystal report file, the exe file, and two merge modules for the crystal...
3
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do...
2
by: mark | last post by:
I've been working on an Access 2000 database for a couple of weeks now. I took a course in access about a year ago, a crash course, and I learned a ton, but I didn't touch Access for the year since...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
4
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.