Hi all,
Sorry, I'm a bit new at this, but I'm trying to get a certain function to work on my Mac (using XCode on Leopard), and I've discovered some weird behaviour. I've atomized the issue down to this code:
Code:
#include <stdio.h>
#include <string.h>
int main (int argc, const char * argv[]) {
char* string;
FILE* filename;
filename = fopen("sample.pdf", "rb");
printf("Enter a string: ");
scanf("%s", string);
printf("Pass before fseek() = %i\n", strlen(string));
fseek(filename,0,SEEK_END);
printf("Pass after fseek() = %i\n", strlen(string));
//printf("String is %i characters long", strlen(string));
return 0;
}
I've been testing with Windows and Mac, but I really need to get this working on the Mac. What happens is, this program takes a string -- it's meant to be a password. However, after doing an fseek operation on a file, it gets very whacky. I'm testing length of the string, and depending on its original length, it either decrements by one, or goes to zero altogether. Here's some sample output:
Code:
Password: asdf
Pass before fseek() = 4
Pass after fseek() = 3
Code:
Password: dkdkd
Pass before fseek() = 5
Pass after fseek() = 0
It works fine in Windows. Any suggestions?
Thanks,
Aaron.