Chéraaar wrote:
"Michael Mair" <Mi**********@invalid.invalid> schreef in bericht
news:3a*************@individual.net...
chéraaar wrote:
never mind, problem solved :)
Grrr, just as I was about to post a corrected version of your code...
No joke.
Cheers ;-)
Michael
hehe sorry, but I'm still interested because I solved it by editing the
files where I'm reading from...
instead of using the scanstring you told me to use I removed all unnecessary
characters so that I have for example:
804520 80453a jle
and I use:
while(fscanf(list, "%lx %lx %s", &address_new[n], &address_jump[n],
&opcode[n])==2) n++;
and this works to read the whole file into these arrays (which I then use to
make the checks), which wasn't working with the unedited version of list...
So if you could point me out why this isn't working with
while(fscanf(list,"New 0x%lx Old 0x%*lx: %*[a-z] %lx%*[^\n]\n", &add_new,
&add_jump) == 2) that would be very nice :)
The whitespace belongs at the beginning, i.e.
" New 0x%lx Old 0x%*lx: %*[a-z] %lx%*[^\n]"
should do.
The code below is not well tested and not the cleanest way to do
it but I was not sure about your intent.
Apart from that, there are tools/languages much better suited to
purposes like that.
Cheers
Michael
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define STRINGIZE(s) #s
#define XSTR(s) STRINGIZE(s)
#define JMP_NAMELEN 4
#define JMP_SCANFMT "%"XSTR(JMP_NAMELEN)"s"
enum jumps { JBE, JAE, JNO, JP, JO, JNP, JA, NUM_COUNTERS };
const char jumpnames[NUM_COUNTERS][JMP_NAMELEN] = {
"jbe", "jae", "jno", "jp", "jo", "jnp", "ja"
};
int main (void)
{
unsigned int count_new = 0, count_jump[NUM_COUNTERS] = {0};
int success;
char buf[JMP_NAMELEN];
unsigned long range_start, range_end, add_new, add_jump;
FILE *list, *diota1, *diota2;
size_t i;
success = 0;
if ( !(list = fopen("list", "r")) ) {
/* Handle error */
}
else if ( !(diota1 = fopen("diota", "r")) ) {
/* Handle error */
fclose(list);
}
else if ( !(diota2 = fopen("diota", "r")) ) {
/* Handle error */
fclose(diota1);
fclose(list);
} else {
success = 1;
}
if (!success) {
fprintf(stderr, "Error opening files\n");
exit(EXIT_FAILURE);
}
success = 1;
while (fscanf(list, " New 0x%lx Old 0x%*lx: " JMP_SCANFMT
" %lx%*[^\n]", &add_new, buf, &add_jump) == 3)
{
if (fscanf(diota1, " [%lx-%lx]%*[^\n]", &range_start, &range_end)
!= 2)
{
success = 0; break;
}
if (add_new >= range_start && add_new <= range_end) {
count_new++;
}
if (fscanf(diota2, " [%lx-%lx]%*[^\n]", &range_start, &range_end)
!= 2)
{
success = 0; break;
}
if (add_jump >= range_start && add_jump <= range_end) {
for (i=0; i<NUM_COUNTERS; i++) {
if (strncmp(jumpnames[i], buf, JMP_NAMELEN) == 0) {
count_jump[i]++;
break;
}
}
if (i == NUM_COUNTERS) {
success = 0; break;
}
}
}
if (!feof(list))
success = 0;
fclose(diota2);
fclose(diota1);
fclose(list);
if (!success) {
fprintf(stderr, "Error while scanning files\n");
exit(EXIT_FAILURE);
}
printf("count_new: %3d\n", count_new);
for (i=0; i<NUM_COUNTERS; i++)
printf("count_jump[%.*s]: %3d\n", JMP_NAMELEN, jumpnames[i],
count_jump[i]);
printf("\n");
return 0;
}
--
E-Mail: Mine is an /at/ gmx /dot/ de address.