精華區beta java 關於我們 聯絡資訊
請問一下下面程式碼怎麼翻譯成 Java ? java 中有沒有 feof() 函數 #include <stdio.h> int main() { int i; char* filename = "1.txt"; char s[100]; FILE* fp = fopen(filename, "r"); if (fp != NULL) { while(!feof(fp)) { fscanf(fp, "%s %d \n", s, &i); printf("%s %d ", s, i); if (!strcmp(s, "Long")) { printf("long\n"); } if (!strcmp(s, "Int")) { printf("int\n"); } } } fclose(fp); return 0; } // 1.txt Int -1166707595 Long 2594814172 Long 2594820957 Int 0 Long 86771 Int 24 Int 0 Long 0 Long 0 Int 0 Int 0 Int 0 Long 6804000 Long 0 Long 0 Long 0 Int 0 Int 0 Int 0 Long 0 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.146.84.72
bleed1979:如果硬要判斷eof的話,建議使用InputStream類的。 03/26 20:26
bleed1979:或是 != null 等,這裡不是C版就不幫改了。 03/26 20:28