I am trying to understand how to read some file from text, and then enter it into an array to save it for later manipulation. I just cant seem to get it. I have tried structs and string arrays but I still cant grasp how to implement this in c. I have successfully been able record at least one line into the array but it copies the same line multiple times. Here is a layout of what my text and code look like.
Text File:
# A demonstration of some simple MIPS instructions
Loop: sll $t1, $s3, 2
add $t1, $t1, $s6
lw $t0, 0($t1)
bne $t0, $s5, Exit
addi $s3, $s3, 1
j Loop
Exit:
.c File:
int assem::readFile(FILE *file) //read file function for file to be read
{
//char String[200];
char lines[20];
char *ptr = lines;
const int MAX = 101;
char myString[MAX];
int i = 0;
while(fgets(&lines[i], 100, file) != NULL)
{
i++;
}
printf("%s\n", lines);