473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help with programming

I am getting some error messages which I can't figure out their
meaning. I have the code setup, I think it's correct but it doesn't
work. My goal is to get this program to read from a data file and
basically put it into an output file that I can access as a test file.
Here is my header file:

#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

struct StudRdType
{
int id;
float exam1;
float exam2;
float exam3;
};
StudRdType students;

void ReadRd(ifstream &, StudRdType[]);
void WriteRd(ofstrea m&, StudRdType[]);

Here is my function file: It is supposed to hit the data file, read it
and save the information. For example the data file looks like:

1111 275 323 432
1342 432 235 532
2343 235 432 234

So the ReadRd function is spoed to read that and save it. I can't get
it do that, im a bit rusty and can't seem to remember how to do this.
This is what I have for the function file (implementation ).

#include "stud2.h"

void ReadRd(ifstream & inFile, StudRdType students[])

{

inFile.get(stud ents.id);

while(inFile)
{
inFile >> students.exam1 >> students.exam2 >> students.exam3) ;
inFile.ignore(' \n');
inFile.get(stud ents.id);
}
}

void WriteRd(ofstrea m& outFile, StudRdType students[])
{
outFile << students.id << students.exam1 << students.exam2 <<
students.exam3 << endl;
outFile.setf(io s::fixed);
outFile.setf(io s::showpoint);
outFile.precisi on(2);
}

For some reason it isn't working , not sure hwy.. Finally here is my
driver file:

#include "stud2.h"

int main()
{

ifstream inFile;
ofstream outFile;
StudRdType students;
inFile.open("in .data");
outFile.open("o ut.data");
if(inFile.fail( ) || outFile.fail())
{
cout << "input or out file opening failed" << endl;
exit(1);
}

ReadRd(inFile, students);
WriteRd(outFile , students);

outFile << "*** END ***" << endl;

return 0;
}
Now here are the errors I get when I run them.. Again my goal is to
read the data file I showed above and print it to an outfile, the exact
same way as it looks.

Errors:

runstud2.cxx: In function `int main()':
runstud2.cxx:40 : error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void ReadRd(std::ifs tream&, StudRdType*)'
runstud2.cxx:41 : error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void WriteRd(std:fst ream&, StudRdType*)'
stud2.cxx: In function `void ReadRd(std::ifs tream&, StudRdType*)':
stud2.cxx:15: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: parse error before `)' token
stud2.cxx:21: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx: In function `void WriteRd(std:fst ream&, StudRdType*)':
stud2.cxx:35: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'

I'm completely Confused.. I am in need of some serious help as I am
eager to learn this stuff and am unsure as to what I'm doing
incorrectly.

Thanks in advance!

Sep 16 '05 #1
3 2665
First up - I am NOT going to give you a correct working program (I
think you're having problems in your homework!)
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <iostream>
#include <fstream>
#include <iomanip>
Errors:
runstud2.cxx: In function `int main()':
runstud2.cxx:40 : error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void ReadRd(std::ifs tream&, StudRdType*)'
This should tell you everything! You are passing an object where a
pointer is expected! All the other errors are also due to this very
mistake. In main, you've said -
StudRdType students;


This is a *single* object and *not* an array of objects. The functions
ReadRd and WriteRd are expecting pointers! Now, go figure it out how to
fix it - you've enough information to do it yourself!

Srini

Sep 16 '05 #2
Drewdog wrote:
I am getting some error messages which I can't figure out their
meaning. I have the code setup, I think it's correct but it doesn't
work.


LOL

You're confused about arrays, and are desparately trying to ignore this
issue in your code.

The easiest answer would be to use a vector instead of an array. But I'm
absolutely positive you won't want to take the easy route (newbies never
do).

So you need to get a C++ book and look up dynamic arrays, that is the
technique you need here.

Alternatively look up vectors. This will be easier in the long run but
mean that you have to throw away more of the code below.

john
Sep 16 '05 #3
On 9/15/2005 7:07 PM, Drewdog wrote:
struct StudRdType
{
int id;
float exam1;
float exam2;
float exam3;
};
StudRdType students;

void ReadRd(ifstream &, StudRdType[]);
void WriteRd(ofstrea m&, StudRdType[]);


If you look closely at your function prototypes, you will notice that
they are expecting to receive an array of StudRdType. The variable you
have defined calles "students" is not an array, it is mearly a variable
of type struct StudRdType. Turn that into an array and most of those
errors should disappear.

--
~Mushr00m Head
http://members.cox.net/mushroomhead/
Sep 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1862
by: mch2k2 | last post by:
Hello All I have just started working on Pyhton. I need urgent help regarding Python Network Programming. I want the elctronic version of the Book: Foundations of Python Network programming by John Goerzen. If anybody among you have that please forward at my mailID. Thank you in advance. Manjeet Chaudhary
45
3045
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
5
2652
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more demand for. Looking at jobs there seems to be a better chance in getting a java job rather than a oracle or c++ job. Also is java and oracle a good combiantion?
2
3892
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
11
2133
by: Larry | last post by:
I will be teaching an eCommerce application development course using ASP.Net after many years of having taught classic ASP. (Course was interrupted by 18 months in the Middle East with my Army Reserve unit.) I need a textbook recommendation for a particular need. As I have delved into ASP.Net I find that I want to teach the course by emphasizing coding in the code behind pages but most of the books targeted at beginners to ASP use...
5
1837
by: Kevin Carne | last post by:
First, Merry Christmas. I have been doing intensive Java programming for two years in school (no choice on the language), but now I need to return to C++ because my resume is filled with it both in Windows and Unix and I need work because I am graduating in a few months. Instead of just reading books to refresh my memory, I'm going to build a large (4 month) project that encompasses all the C++ material. I think this is a better way of...
9
5254
by: Brian Hampson | last post by:
I am trying to determine all the groups which the current user has permissions to add a member. Here's my code: foreach (System.DirectoryServices.SearchResult ADSearchres in ADSearch.FindAll()) { //ActiveDs.ADSearchres.Properties
5
3370
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that I could better understand the concept, he was trying to convey to me. I ran my own example and it crashed and burn "what a surprise!" : (. I ran the authors example out of the book and quess what, it crashed also, : 0. I ran them both on my...
2
1838
by: dydx13 | last post by:
Hello there, Basically, what I want to do is to develop a GUI-based file sharing program for myself. This is strictly for educational purposes only. Do you know of any good books out there that can point me in the right direction? I am a novice/intermediate C++ programmer. I took a c++ programming class at a local community college a few years ago and I'm now trying to relearn the language. I've never made a large-scale computer...
2
1841
by: _A_C-ker_ | last post by:
Hello geek(s), I'm in desperate need of graphics programming using C language. Does anyone have material or web-links that explain graphics programming in- detail? I would appreciate your help in this matter. Thanks, _A_C-ker_ (a seeker)
0
8774
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
9447
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
9307
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
9235
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
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4550
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...
1
3261
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 we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.