Hey there,
I've been working on this problem for a while, using "good" programming techniques by breaking the problem up into smaller chunks and working on them. You guys have been real helpful so far, now I'm a couple of steps away from finishing my code, I think. I've been able, through a lot of help from you guys, to hard code in a string of IntelHEX code and perform operations on that, now I'd like to move onto the actual file itself. So, as of now, I'm able to open up the file and have it print out onto my output screen. From here, I need to be able to save that output into a character array so I can then perform my other subroutines and break down this code into useful data...useful for humans, I should say.
(hope I got that code posting thingee right too!!) Anyway, that's that problem. If you guys could help me out, I'd appreciate it. I was thinking of using strcpy, but don't know exactly how to use it. hex2 is the char array I've been using in my other routines to store in the hard coded input string.Code:typedef void (*ReadLineFunc)(const char *); int ReadLines(const char *Filename, ReadLineFunc Callback) { FILE *fp = fopen("filename", "r"); char hex2[512]; int m=1; if(fp == NULL) { fprintf(stderr,"Error, file is not found. \n"); return -1; } /* Read each line and print it out */ for(m=1;m<40;m=m+1) { if(fgets(hex2, 512, fp) == NULL) { /* No more lines to read */ break; } Callback(hex2); } fclose(fp); return 0; } void MyReadLineFunc(const char *Line) { /* Prints out all except the first character */ if(Line[0]) puts(&Line[1]); }
Cheers