scanf sucks >.<;

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6376 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michiel Van Der Kolk 2005-04-28 17:03:45 +00:00
parent 8c0dfb4d14
commit a43f90f563

View file

@ -28,7 +28,7 @@ main() {
int done=0; int done=0;
printf("Output filename? "); printf("Output filename? ");
fflush(stdout); fflush(stdout);
scanf("%s",buf); fgets(buf,254,stdin);
fp=fopen(buf,"w"); fp=fopen(buf,"w");
if(fp<0) { if(fp<0) {
printf("Error opening outputfile.\n"); printf("Error opening outputfile.\n");
@ -41,13 +41,13 @@ main() {
printf("(arguments:) NUMBER=14 NUMBERFIELD=15 STRING=16 STRINGFIELD=17\n"); printf("(arguments:) NUMBER=14 NUMBERFIELD=15 STRING=16 STRINGFIELD=17\n");
printf("Token kind? "); printf("Token kind? ");
fflush(stdout); fflush(stdout);
scanf("%d",&num); fgets(buf,254,stdin);
token.kind=num; token.kind=strtol(buf,0,10);
memset(&token.spelling,0,256); memset(&token.spelling,0,256);
if(token.kind==TOKEN_STRING) { if(token.kind==TOKEN_STRING) {
printf("Token spelling? "); printf("Token spelling? ");
fflush(stdout); fflush(stdout);
scanf("%s",&token.spelling); fgets(token.spelling,254,stdin);
} }
if(token.kind==TOKEN_STRINGIDENTIFIER) if(token.kind==TOKEN_STRINGIDENTIFIER)
printf("TITLE=4 ARTIST=5 ALBUM=6 GENRE=7 FILENAME=8\n"); printf("TITLE=4 ARTIST=5 ALBUM=6 GENRE=7 FILENAME=8\n");
@ -59,8 +59,8 @@ main() {
token.kind==TOKEN_NUM) { token.kind==TOKEN_NUM) {
printf("Token intvalue? "); printf("Token intvalue? ");
fflush(stdout); fflush(stdout);
scanf("%d",&num); fgets(buf,254,stdin);
token.intvalue=num; token.intvalue=strtol(buf,0,10);
} }
fwrite(&token,sizeof(struct token),1,fp); fwrite(&token,sizeof(struct token),1,fp);
done=token.kind==0; done=token.kind==0;