Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey guys,

i'm currently making a virtual machine in c for a community project, no one else is willing to make one. i would have done it in C# which is my normal language, but part of the project said that it couldn't be reliant on any framwork or libraries. so we all decided that the virtual machine would be made in c and i was the person hat volunteered to make it.

so i got to work as quickly as possible learning how to program in c and then making my virtual machine. it's coming along nicely, except there's one major part of the virtual machine that i don't know how to do, how to read text from a file and then put it into an array.

so what i want to find out is how to read the contents of a file and then put it into an array. the array that i have to put the code in is called 'program'.

and when the contents is loaded into the array, is it possible to split it up at every newline or at every ' ' character? that would help a lot.

thanks for all your help,
Fletcher
Posted
Updated 6-Oct-13 18:20pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Oct-13 0:23am    
I hardly can imagine anyone working at such a project like a virtual machine but unable to load a file. How you do it actually depends on the file format and on how you want to have some data in a file. At least show what did you try so far.
Please see: http://whathaveyoutried.com.
—SA
Member 8378691 7-Oct-13 2:57am    
i am working on a virtual machine, don't doubt that. but at the moment, all of the parts code is already put into an array which is then run through the virtual machine. i don't know how to read from an outside file yet, and i thought that txt would be easiest and so i'll start with that and then move onto binary files and all that.
Richard MacCutchan 7-Oct-13 4:05am    
You read a file using the standard C library functions. As SA says it is hard to believe that you can write the code for a virtual machine and yet cannot do something as basic as reading a file into an array.
Sergey Alexandrovich Kryukov 7-Oct-13 4:19am    
OP says "don't doubt". Okay, I don't doubt anymore. It actually depends on what one calls "working"... :-)
—SA
Richard MacCutchan 7-Oct-13 4:29am    
Maybe we will see a demonstration some time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900