我开始学习C,目前正在编写一个基于文本的彩票游戏。但是我需要一种在游戏结束时存储价值的方法,因此可以保留下一个游戏。我在下面做了一个更简单的代码,代表了我需要的东西。请帮忙。
#include <stdio.h>
int main() {
//TODO get "int saved" from save.txt
printf("Value saved: %d\n", saved);
printf("Add: ");
int add;
scanf("%d", &add);
int new = saved+add;
printf("New value: %d\n", new);
//TODO save "int new" to save.txt
}
save.txt的:
100
答案 0 :(得分:0)
试试这个
// Getting range
public List<Dates> getRange(long dataStart, long dataEnd) {
List<Dates> datesList = new ArrayList<Dates>();
String selectQuery = "SELECT * FROM " + TABLE_RESULTS_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.query(TABLE_RESULTS_NAME, new String[]{KEY_ID,
KEY_DATA, KEY_COUTER}, KEY_DATA + " BETWEEN ? AND ? ", new String[]{String.valueOf(dataStart),String.valueOf(dataEnd)},null, null, null, null);
// looping through all rows and adding to list
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
Dates dates = new Dates();
dates.set_id(Integer.parseInt(cursor.getString(0)));
dates.set_data(cursor.getLong(1));
dates.set_counter(cursor.getInt(2));
// Adding contact to list
datesList.add(dates);
}
// return dates list
return datesList;
}