G
gb
Hi,
I have a small program which opens a file (Whose content is a mac
address in the form xx:xx:xx:xx:xx:xx) and uses fscanf() to get
individual bytes into an array which is defined as "unsigned char
macaddress[6]". The strange thing is that it prints zeroes on MIPS
processor where as it works correctly on x86 systems. Appreciate if
some body could help to understand the fscanf() behavior.
Here is the code I am using:
#include <stdio.h>
main()
{
FILE *fp;
unsigned char macaddress[6];
char buf[50];
fp = fopen("/tmp/macaddress", "r" );
if (fp == NULL ) {
printf("Couldn't open the file \n");
return -1;
}
fscanf(buf,"%x:%x:%x:%x:%x:%x",
&macaddress[0],&macaddress[1],&macaddress[2],&macaddress[3],&macaddress[4],&macaddress[5]);
printf("MAC address: %x:%x:%x:%x:%x:%x\n",macaddress[0],
macaddress[1], macaddress[2], macaddress[3], macaddress[4],
macaddress[5]);
fclose(fp);
}
Thanks in Advance
--gb
I have a small program which opens a file (Whose content is a mac
address in the form xx:xx:xx:xx:xx:xx) and uses fscanf() to get
individual bytes into an array which is defined as "unsigned char
macaddress[6]". The strange thing is that it prints zeroes on MIPS
processor where as it works correctly on x86 systems. Appreciate if
some body could help to understand the fscanf() behavior.
Here is the code I am using:
#include <stdio.h>
main()
{
FILE *fp;
unsigned char macaddress[6];
char buf[50];
fp = fopen("/tmp/macaddress", "r" );
if (fp == NULL ) {
printf("Couldn't open the file \n");
return -1;
}
fscanf(buf,"%x:%x:%x:%x:%x:%x",
&macaddress[0],&macaddress[1],&macaddress[2],&macaddress[3],&macaddress[4],&macaddress[5]);
printf("MAC address: %x:%x:%x:%x:%x:%x\n",macaddress[0],
macaddress[1], macaddress[2], macaddress[3], macaddress[4],
macaddress[5]);
fclose(fp);
}
Thanks in Advance
--gb