473,793 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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.da t", "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 1410
Banfa
9,065 Recognized Expert Moderator Expert
http://www.thescripts.com/forum/thread657086.html
Aug 6 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:
void Arrays (int numArray[], int quantity[])

{
FILE *fp;
fp = fopen("stock.da t", "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 New Member
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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
3138
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 SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
4
6196
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 report (crystal_managed2003.msm and crystal_Database_Access2003.msm). when i installed it on a different computer before running it. i verify the neccessary files was added. when i ran it, it return "Cannot find KeycodeV2.dll, or invalid keycode."
3
1593
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 seems to get me any closer to the solution. Below is a program that I am working on for a class project. The original code was provided for us which is what I have below. What we have to do is make the app run so that it allows the user to add...
2
2563
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 then so I forgot everything I learned : ( So this little project I envisioned has turned out to be much harder than I thought. But I think I'm close with it, so I want to see it through. What I wanted to create is a database that will track my...
23
3290
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 to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
4
4152
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 context help with that particular command. In VB6 this was easy, since each menu item had a "helpId" property. That doesn't seem to be the case in VB.NET. Am I wrong about that, or (alternatively) is there some other way to accomplish this? --
16
2540
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
16
2820
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 efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
10
3368
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 the worst I ever seen. I almost cannot find anything I need, including things I
0
5577
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9670
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.