What i need to do is open a text file in C and output each line into a new array key.
Input files with C++
Collapse
X
-
What have you tried?
I can help with specific questions but I cannot be your C/C++ instructor.
Please read the posting guidelines. -
This isn't even a real attempt. The mistakes you made suggest you aren't familiar with the material, or any of the previous concepts required for this problem. If the reason you're having trouble is not knowing the material, then the solution is obvious. Learn C++.
Here's what makes me think you have no idea what is going on.
- Use of C code. FILE pointers, fopen, fscanf, fclosef, printf, etc. are all in the C library. You said C++? Did you just copy random code from the internet?
- Incorrect use of fscanf. %lf is the format specifier for a double. words is a char. This code will probably trash memory. At runtime, you may also see the program segfault here. Doesn't matter though. There's something seriously wrong with that line.
- You follow the line with a printf statement. Once again, you specify the format as a double. Yet use a char. Furthermore, the char is unitinitialized , leading to garbage.
- Then you close the file. Eh?
- Commented out code includes repeated printf statements (huh?) and another guess at how fscanf works.
Most of your code is nonsense. It's not presented as a compileable format either. There isn't anything to fix here. Fixing means you have something that could be made to work. You don't. Look up your class notes. If you don't have class notes, look at your book, or perhaps look at cprogramming.co m and cplusplus.com . Read the tutorials.
This will take you time. I hope if this is an assignment with a deadline, you have a long time before the deadline.
EDIT: I just did a reread. You mention in the title C++. Your post mentions C. Do you even know which language you are using?Comment
Comment