I really need some help with my last assignment of the semester. I cant figure out how to pass arrays to functions. I have been thinking it would work best if I used pointers but I really dont know hoe to use them very well. I just need my program to...
1. Read 100 integers from a txt file.
2. Put them into a 10 x 10 array
3. Then pass the array to displayArray where it displays 10 numbers across & 10
down
So I started out by writing everything in intmain() to make sure I could at least read and display everything. Then I started breaking it all up. So really the only problems should be in calling functions and/or passing the array.
I am probably way off and could really use help. Here is my code ATM. I will update it if I feel I have made a bit more progress on my own.
Scroll towards the bottom of this tutorial or if you have the time, read the whole thing. It sounds like you need a basic tutorial on passing arrays to functions. The solution will be obvious once you read the information at this link. http://cplusplus.com/doc/tutorial/arrays/
well after reading that and doing some more research I have made it farther now and think that I am extremely close to having it work.
My current problem is that it compiles just fine but instead of filling the table with numbers from the text file, it is filling it up with "-858993460" for all 100 integers. So I think its some small error that I am just not seeing. There are 0 errors or warnings.
Edit: nvm, didn't read first post properly. Although I now have some work to challenge myself.
I still think that declaration won't work as you saying put the whole file into the current element.
remember myfile is the file, so basically what you want to do is split myfile up
you can use getline(myfile, line); but this will give you each line in the file as a string. so you would need to split this up further and cast to int. There's probably a better way of doing that.
Also being that your array is using constants, your functions can use those constants as well, this doesn't make any difference to your program, however, just a tip. you can also make your array a class field which means you wouldn't need to pass it to each function and could continue just using the constants. (yep I'm lazy :) )