Ok, we got an assignment that includes using of malloc(), realloc() and pointers. That confuses the living shit out of me. For beggining we have to scan a file where there are words with a sequence of number next to them. I would like to scan the two and put them in two different arrays(char[] and double[][] ???) or pointers. The problem is, that i don't even know how to start
example of text file
[code]
apple 30.2 2.00001 1234.6 2.0 3.0 2.01 1.99 -99999
shovel -56 -1 457 22 2.2 2.1 1 -99999
japan 3 2.999 3.001 2 1 1 4 3 300.1 -99999
[/code]
Oh, and -99999 means "end" of the sequence(it mustn't be included)
So I had to make a program that reads a database.txt and prints the information in readable way.
In said database are games.
[code]
NAME(string)###DEVELOPER(string)###RELEASE_YEAR(int)###GENRE###COMPLETED(bool)###MY_RATING(int) //format
Random games that I have played. // Introduction to my database
###
Dwarf Fortress###Tarn Adams###2006###Roguelike strateegia###0###9
Age of Empires II: The Age of Kings###Ensemble Studios###1999###Real-time strateegia###1###9
Heroes of Might and Magic III###New World Computing###1999###Turn-based strateegia###0###8
SimCity 4: Deluxe Edition###Maxis###2003###City-building###0###8
Half-Life 2###Valve Corporation###2004###FPS###1###10
etc.
etc.
[/code]
Now the main program must read the database and first print the character count. This I achieved without many problems.
However I now have to present these games in readable fashion.
e.g. "Half-Life 2 developed by Valve Corporation. Released : 2004. Genre : FPS. Game completed. My rating : 10/10"
So far I have only read the contents of database.txt into a buffer. However I can't quite figure out how to read a line in said database buffer and how to add information to variables ignoring the ###'s
Like add Half-Life 2 to "name" and Valve Corporation to "developer" etc.
Should I use std::istream::getline with a delimiting character "#" ? But how then I point getline to a certain line in database buffer?
__
forgot to mention : C++
I'm pretty sure you can do a string split on your input line, with "###" as the separator, which'll give you an string array, which you can then use to get your variables by doing like this
[cpp]printf(gameInfo[2]);[/cpp]
To get the release year.
[QUOTE=RandomDexter;39935838]Ok, we got an assignment that includes using of malloc(), realloc() and pointers. That confuses the living shit out of me. For beggining we have to scan a file where there are words with a sequence of number next to them. I would like to scan the two and put them in two different arrays(char[] and double[][] ???) or pointers. The problem is, that i don't even know how to start
example of text file
[code]
apple 30.2 2.00001 1234.6 2.0 3.0 2.01 1.99 -99999
shovel -56 -1 457 22 2.2 2.1 1 -99999
japan 3 2.999 3.001 2 1 1 4 3 300.1 -99999
[/code]
Oh, and -99999 means "end" of the sequence(it mustn't be included)[/QUOTE]
Maybe use a struct:
[cpp]struct entry {
char *name;
double *contents;
};
...
struct entry *entries = calloc(START_CT, sizeof(struct entry));
[/cpp]
Realloc will come into play when the number of entries exceeds START_CT, and when you're adding the doubles to the contents of each entry. You'll malloc() the name as well.
[editline]16th March 2013[/editline]
And you can parse the file with strtok
[QUOTE=account;39936220]Maybe use a struct:
[cpp]struct entry {
char *name;
double *contents;
};
...
struct entry *entries = calloc(START_CT, sizeof(struct entry));
[/cpp]
Realloc will come into play when the number of entries exceeds START_CT, and when you're adding the doubles to the contents of each entry. You'll malloc() the name as well.
[editline]16th March 2013[/editline]
And you can parse the file with strtok[/QUOTE]
Sorry but this is already too complicated for me D: Can you give me any other hint on how would i proceed with this. The first part of the asignment is, that you scan this file, in the second part the user inserts a few numbers and the program finds the word that most fits to that input
Okey, let me ask it this way, how would i read the words and put them in one array, and read numbers that are adjacent to them and put them in other array?
I need some help with my text class. When I have 1 Text that is updating every frame ( the frames per second counter in the top of the screen ) the game runs at a smooth 60 frames per second. However as soon as I add another Text that updates every frame it drops to like... 20. I am fairly sure it has to do with the way I am loading the sprites each frame when the text is changed. If somebody could help me out on what kinds of optimizations to make that would be awesome. I tried to do something where it would only update the letters that changed but I couldn't figure that out.
[CODE]
public class Text extends Entity{
private String text;
private String fontSheet;
private Quad[] quads;
public Text(String string){
text = string;
fontSheet = "res/fontSheet.png";
quads = new Quad[text.length()];
for(int i = 0; i < text.length(); i++){
quads[i] = new Quad();
quads[i].scale = scale;
quads[i].position = new Vector3f(position.x + (i * 1),position.y,position.z);
int ci = text.charAt(i);
int column = (ci % 16);
int row = (ci / 16);
quads[i].texture.loadSprite(column, row, fontSheet);
}
}
public void tick(){
for(int i = 0; i < quads.length; i++){
quads[i].tick();
}
}
public void setText(String newText){
if(newText != text){
text = newText;
quads = new Quad[newText.length()];
for(int i = 0; i < newText.length(); i++){
quads[i] = new Quad();
quads[i].scale = scale;
quads[i].position = new Vector3f(position.x + (i * 1),position.y,position.z);
int ci = text.charAt(i);
int column = (ci % 16);
int row = (ci / 16);
quads[i].texture.loadSprite(column, row, fontSheet);
}
}
}
}
[/CODE]
[QUOTE=Gulen;39936175]I'm pretty sure you can do a string split on your input line, with "###" as the separator, which'll give you an string array, which you can then use to get your variables by doing like this
To get the release year.[/QUOTE]
[QUOTE=account;39936220]
And you can parse the file with strtok[/QUOTE]
Thanks for the help.
I then figured it out and completed the whole program. It all worked. Like literally I was about to submit it to my lecturer but I decided to open it in another IDE. Which in turn with my help I am afraid it fucked it up. I get invalid Null pointer error after compiling in both IDE's (first one was visual studio, second was dev-c++).
[cpp]void kirjed(char * puhverdus)
{
int i;
minu.name[0] = strtok (puhverdus,"#");
for (i = 0;i<16;i++)
{
minu.name[i] = strtok (NULL,"#");
minu.dev[i] = strtok (NULL,"#");
minu.year_str[i] = strtok (NULL,"#");
minu.year[i] = atoi (minu.year_str[i].c_str());
minu.genre[i] = strtok (NULL,"#");
minu.completed_str[i] = strtok (NULL,"#");
if (minu.completed_str[i] == "1")
{
minu.completed[i] = true;
}
else
{
minu.completed[i] = false;
}
minu.rating_str[i] = strtok (NULL,"#");
minu.rating[i] = atoi (minu.rating_str[i].c_str());
}
}[/cpp]
I shit you not, it all used to work. But after opening the cpp file in dev-c++ ide it started giving me invalid null pointer error which I tracked to that part of the code. I have not messed with it yet, but it used to work. That's what amazes me most.
[cpp]minu.name[i] = strtok (NULL,"#");[/cpp]
I tried commenting shit out and rerunning. Found out its this line that is causing problems. Could it be that it shouldn't be NULL at the beginning of the loop ?
__________
Figured it out. I had messed up my database file where I had to take the information.
###Dwarf Fortress###Tarn Adams###2006###Roguelike strateegia###0###9
This for example was the line to take information from. I was missing 3 dashes in front of the name.
So many problems from my own fucking mishaps.
[QUOTE=RandomDexter;39944817]Sorry but this is already too complicated for me D: Can you give me any other hint on how would i proceed with this. The first part of the asignment is, that you scan this file, in the second part the user inserts a few numbers and the program finds the word that most fits to that input
Okey, let me ask it this way, how would i read the words and put them in one array, and read numbers that are adjacent to them and put them in other array?[/QUOTE]
I started something but i crashes, nothing new -.-
[code]FILE *file;
int main(FILE *file){
char cuewords [1000][99];
double numerals [1000][99];
char temp[99];
int counter;
file = fopen ("File000.txt", "rt");
int n;
while(n = fscanf(file, "%s", temp) != EOF || n > 0){
fscanf(file, "%s", temp);
if(atof(temp) == 0){
cuewords[counter][sizeof(temp)] = temp;
counter++;
}
else{
numerals[counter][sizeof(temp)] = atof(temp);
counter++;
}
}
}
[/code]
Now, how do i scan lines separately?
[cpp]FILE *file;
int main(int argc, char **argv) {
[/cpp]
main() takes these arguments which are the count of arguments and an array of strings. It doesn't take a FILE *. That said, you could just do int main(void) since you're not using any command-line arguments.
[cpp]while(n = fscanf(file, "%s", temp) != EOF || n > 0){
fscanf(file, "%s", temp);
[/cpp]Get rid of the second fscanf - you've already done the scan in the while(n = fscanf(.... part
Also, I think you can use fgets() to read line-by-line.
[cpp]fgets(temp, MAX_CHARS, file);[/cpp]
It'll read until it either sees a newline or reads MAX_CHARS characters.
[cpp]
if(atof(temp) == 0){
cuewords[counter][sizeof(temp)] = temp;
counter++;
}
else{
numerals[counter][sizeof(temp)] = atof(temp);
counter++;
}
}
}
[/cpp]
I'm not sure what you're doing here - but sizeof(temp) is not what you want. It gives the size of temp as a pointer, which is either 4 or 8, always. If you want the string length of temp, use strlen(temp). You're also setting a char to a char * in the first assignment: cuewords[counter][sizeof(temp)] is a char. You just want to set cuewords[counter] to temp.
[cpp]while((fscanf(fp, "%c", &buffer) != EOF));
{
printf("%c ", buffer);
}[/cpp]
Any idea why this is only printing one letter (that's not in the file) rather than the entire thing?
[B]NEVERMIND I'M AN IDIOT[/B]
Does anyone know why I'm getting artifacts in the distance of this scene?
I've got a feeling it's to do with just adding each spectrum snapshot to a list and not managing memory, as it tends to happen once the program has been running for a certain duration.
[img]http://puu.sh/2jQNk/10de021b72[/img]
Okay, so how would I go about adding stuff up in a row in a CSV file and appending that to the end of the row, then doing that for every row available using C?
[QUOTE=DoctorSalt;39889398]Hey, so I just got Visual Studio 2012 to cooperate with their git extension. Now I tried to create a new branch, but whenever I do it displays this:
[IMG]http://i.imgur.com/L3Wn3zm.png[/IMG]
Very cryptic to me, google was useless. Also, I didn't seem to have this problem in my trivial little test program to figure git out.
EDIT: Before someone says, "just learn to use git normally", I've tried so hard, but it seems with git there is no abstractions, just a giant semi-consistent mess of commands geared towards experienced devs; I just can't do it.[/QUOTE]
What do you find confusing about git? I don't get how people can be writing even remotely complex programs and not understand git unless it's just a matter of giving up before it clicks? GUIs are nice for things like viewing history, but for actually making commits and branching and all that good stuff I definitely prefer the command line.
I'm making a java game in school and I want to implement networking using TCP to play with my friends. I know the actual programming part, but Novell doesn't let me unblock the program from the firewall, which leaves me hanging. I've tried several ways of unblocking the program using both "netsh" and programmically using C# with "COM Interop", but neither allows me cause I'm not administrator, sounds about right.
What I don't find right is that when I check the firewall exceptions list I see that "spotify.exe" is an exception in the firewall, I know for fact that the school hates spotify due to it "slowing down internet" so it can't be the network admins who added it, it probably got added during installation. How does spotify add an exception but I can't? Is there some way to add without having administrator access?
I can access regedit and all folders on the system, change too. If that helps.
I've been getting this kinda weird error in my Android app. I've got this ListView with a list of stations, 33 in total, which is populated by an ArrayList with my own class, from a JSON file through a ListAdapter and Fragment.
What happens is that the list is populated, and draws well, but when I try to scroll down, I get an "Exception dispatching input event" and a NullPointerException (at the stations.add() in StationsListFragment)
My code is this:
StationsListFragment:
[cpp]package com.LarsHelo.radnorpro;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;
import com.LarsHelo.radnor.Station;
public class StationsListFragment extends ListFragment {
RadiationMainActivity activity;
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
activity = (RadiationMainActivity) getActivity();
AsyncTask requester = new JsonRequester(getActivity()).execute(JsonRequester.STATION_LIST_LATEST);
ArrayList<Station> stations = new ArrayList<Station>();
try{
JSONObject result = (JSONObject) requester.get();
JSONArray station_list = result.getJSONArray("stations");
for(int i = 0; i < station_list.length() / 2; i++){
JSONObject station = (JSONObject) station_list.get(i);
double[] readings = {station.getDouble("latestreading")};
double latitude = station.getDouble("latitude");
double longitude = station.getDouble("longitude");
String name = station.getString("name");
String img_url = "http://radnett.nrpa.no/img.php?sid=165049_pic";
stations.add(new Station(latitude, longitude, readings, name, img_url));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StationsListAdapter adapter = new StationsListAdapter(activity, stations);
setListAdapter(adapter);
}
@Override
public void onListItemClick(ListView list, View v, int position, long id){
Intent intent = new Intent(v.getContext(), StationDetailActivity.class);
intent.putExtra("station_id", position);
startActivity(intent);
}
}[/cpp]
StationsListAdapter:
[cpp]package com.LarsHelo.radnorpro;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.LarsHelo.radnor.Station;
public class StationsListAdapter extends BaseAdapter {
ArrayList<Station> stations;
LayoutInflater inflater;
public StationsListAdapter(Context context, ArrayList<Station> stations_array){
inflater = LayoutInflater.from(context);
stations = stations_array;
}
@Override
public int getCount() {
return stations.size();
}
@Override
public Object getItem(int position) {
return stations.get(position);
}
@Override
public long getItemId(int position) {
return position; // Why does this even exist?
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
convertView = inflater.inflate(R.layout.stations_item, parent, false);
holder = new ViewHolder();
TextView station_list_name = (TextView)convertView.findViewById(R.id.list_station_name);
holder.txtName = station_list_name; // (TextView) convertView.findViewById(R.id.station_list_name);
holder.txtLastValue = (TextView) convertView.findViewById(R.id.list_station_value);
} else {
holder = (ViewHolder) convertView.getTag();
}
Station station = stations.get(position);
holder.txtName.setText(station.GetName());
holder.txtLastValue.setText(Double.toString(station.GetLatestReading()));
String[] months = parent.getResources().getStringArray(R.array.months);
holder.txtLastValue.setTextColor(parent.getResources().getColor(R.color.safe_rad_value));
return convertView;
}
static class ViewHolder{
TextView txtName;
TextView txtLastValue;
}
}[/cpp]
I'm working on cross platform game in MonoGame using OpenTK. I want to create some simple gui elements as child elements of my game window. How might i do this?
Here's some basic code to give a jist of what i am doing.
[code]
// GameInstance derives from the Game class, which has a Window member.
[STAThread]
static void Main()
{
_game = new GameInstance();
_game.Run();
}
// This is called in another file. Game represents the GameInstance ^^^
PropertyMenu menu = new PropertyMenu( Game.Window.Handle );
// This is the PropertyMenu's skeleton.
public class PropertyMenu : Form
{
public PropertyMenu( IntPtr handle )
{
Button b = new Button();
b.Text = "Click Me!";
b.Click += new EventHandler( Button_Click );
Control.FromHandle( handle ).Controls.Add( b ); // this gives a null pointer exception so idk what the hell is wrong with my handle.
}
private void Button_Click( object sender, EventArgs e )
{
MessageBox.Show( "Button Clicked!" );
}
}
[/code]
I've read a bunch of outdated and hacky tutorials and i just want to create some child forms for my main game window without any shitty messy workarounds... Do i need to alter the game's window (as in, actually create a separate form then replace the GameInstance's Window with the new form) in order to create child forms properly?
Hey, so I am working on an app, and I just started learning SQLite for android, apparently I am stuck for 3 days now on one problem.
Whenever I try to run query to SUM Up fields from table where month is equal to specific month, I get NullPointer thrown.
[CODE] package com.example.droid;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.example.droid.SqDb;
import android.accounts.Account;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.text.format.DateFormat;
import android.util.Log;
public class DbCon {
private static SQLiteDatabase database;
private SqDb SqHelper;
private String[] UserColumns =
{
SqDb.ACCOUNT_ID,
SqDb.ACCOUNT_NAME,
SqDb.ACCOUNT_USERNAME,
SqDb.ACCOUNT_PASSWORD,
SqDb.ACCOUNT_AGE,
SqDb.ACCOUNT_CITY,
SqDb.ACCOUNT_COUNTRY
};
private String [] GuestColumns =
{
SqDb.GUEST_ID,
SqDb.GUEST_NAME
};
private String [] TransColumns =
{
SqDb.TRAN_ID,
SqDb.TRAN_DESC,
SqDb.TRAN_TYPE,
SqDb.TRAN_TIME,
SqDb.TRAN_DAY,
SqDb.TRAN_MON,
SqDb.TRAN_YEAR,
SqDb.TRAN_CAT,
SqDb.TRAN_VAL
};
private static DbCon myDCon;
DbCon(Context context)
{
SqHelper = SqDb.getInstance(context);
}
public static DbCon getInstance(Context context)
{
if(myDCon == null)
{
myDCon = new DbCon(context.getApplicationContext());
}
return myDCon;
}
public void open() throws SQLException
{
database = SqHelper.getWritableDatabase();
}
public void close()
{
SqHelper.close();
}
public void createUser(String username, String password, String name, String Age, String City, String Country)
{
ContentValues values = new ContentValues();
values.put(SqDb.ACCOUNT_USERNAME, username);
values.put(SqDb.ACCOUNT_PASSWORD, password);
values.put(SqDb.ACCOUNT_NAME, name);
values.put(SqDb.ACCOUNT_AGE, Age);
values.put(SqDb.ACCOUNT_CITY, City);
values.put(SqDb.ACCOUNT_COUNTRY, Country);
database.insert(SqDb.ACCOUNT, null, values);
}
public void createGuest(String name)
{
ContentValues values = new ContentValues();
values.put(SqDb.GUEST_NAME, name);
database.insert(SqDb.GUEST, null, values);
}
public void AddTask(String desc, String type, String cat, double Value)
{
ContentValues values = new ContentValues();
values.put(SqDb.TRAN_DESC, desc);
values.put(SqDb.TRAN_TYPE, type);
values.put(SqDb.TRAN_CAT, cat);
values.put(SqDb.TRAN_VAL, Value);
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
String timedata = df.format(cal.getTime());
String[] whens = timedata.split(" ");
String time = whens[1];
String[] dates = whens[0].split("/");
values.put(SqDb.TRAN_TIME, time);
values.put(SqDb.TRAN_DAY, dates[2]);
values.put(SqDb.TRAN_MON, dates[1]);
values.put(SqDb.TRAN_YEAR, dates[0]);
database.insert(SqDb.TRAN, null, values);
}
Calendar cal = Calendar.getInstance();
public int getMonthInt(){
int month = cal.get(Calendar.MONTH);
return month;
}
public double CountMonthExp()
{
double din = 0;
this.open();
Cursor c = database.rawQuery("SELECT sum("+SqDb.TRAN_VAL+") as"+SqDb.TRAN_VAL+" FROM "+SqDb.TRAN+" WHERE "+SqDb.TRAN_TYPE+"=EXPENDITURE and "+SqDb.TRAN_MON+"=3", null);
if(c.moveToFirst()){
din = c.getDouble(0);
}
else{
din = 0;
}
return din;
}
}[/CODE]
Any suggestions?
And yes the table is created well and working, I tested inserting records works fine.
Here is the error:
[CODE]> 03-19 00:18:38.119: E/AndroidRuntime(19822): FATAL EXCEPTION: main
> 03-19 00:18:38.119: E/AndroidRuntime(19822):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.example.droid/com.example.droid.Hist_act}:
> android.database.sqlite.SQLiteException: no such column: EXPENDITURE:
> , while compiling: SELECT sum(tran_val) astran_val FROM tran WHERE
> tran_type=EXPENDITURE and tran_mon=3 03-19 00:18:38.119:
> E/AndroidRuntime(19822): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.os.Handler.dispatchMessage(Handler.java:99) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> android.os.Looper.loop(Looper.java:130) 03-19 00:18:38.119:
> E/AndroidRuntime(19822): at
> android.app.ActivityThread.main(ActivityThread.java:3687) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> java.lang.reflect.Method.invokeNative(Native Method) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> java.lang.reflect.Method.invoke(Method.java:507) 03-19 00:18:38.119:
> E/AndroidRuntime(19822): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> dalvik.system.NativeStart.main(Native Method) 03-19 00:18:38.119:
> E/AndroidRuntime(19822): Caused by:
> android.database.sqlite.SQLiteException: no such column: EXPENDITURE:
> , while compiling: SELECT sum(tran_val) astran_val FROM tran WHERE
> tran_type=EXPENDITURE and tran_mon=3 03-19 00:18:38.119:
> E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteCompiledSql.native_compile(Native
> Method) 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> com.example.droid.DbCon.CountMonthExp(DbCon.java:122) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> com.example.droid.Hist_act.onCreate(Hist_act.java:42) 03-19
> 00:18:38.119: E/AndroidRuntime(19822): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
> 03-19 00:18:38.119: E/AndroidRuntime(19822): ... 11 more
[/CODE]
Help? stuck for 3 days now.
I am sure there is some simple small problem in it, but I am just too retarded to find it, help?
[editline]19th March 2013[/editline]
nevermind, I was right - I was too retarded to spot the problem.
I had =EXPENDITURE while it had to be ='EXPENDITURE'
Fucking idiot.
P.S - I wonder can I be banned for flaming at myself?
So In reference to my tetris problem, I've got this so far:
[code] private class Key extends KeyAdapter
{
public boolean keyDown(Event e, int key)
{
//right paddle
if(key == 1005)
{
rpaddle_up = true;
}
if(key == 1004)
{
rpaddle_down = true;
}
//left paddle
if(key == 115)
{
lpaddle_up= true;
}
if(key == 119)
{
lpaddle_down=true;
}
//x key = exit
if(key == 'x')
System.exit(0);
return true;
}
public boolean keyUp(Event e, int key)
{
//right paddle
if(key == 1005)
{
rpaddle_up = false;
}
if(key == 1004)
{
rpaddle_down = false;
}
//left paddle
if(key == 115)
{
lpaddle_up= false;
}
if(key == 119)
{
lpaddle_down=false;
}
return true;
}
}[/code]
All I need now is something that tells the paddles what to do once rpaddle_up is true and lpaddle_down is true, etc. Where should I put that and what should it say?
[QUOTE=prooboo;39969602]So In reference to my tetris problem, I've got this so far:
[code] private class Key extends KeyAdapter
{
public boolean keyDown(Event e, int key)
{
//right paddle
if(key == 1005)
{
rpaddle_up = true;
}
if(key == 1004)
{
rpaddle_down = true;
}
//left paddle
if(key == 115)
{
lpaddle_up= true;
}
if(key == 119)
{
lpaddle_down=true;
}
//x key = exit
if(key == 'x')
System.exit(0);
return true;
}
public boolean keyUp(Event e, int key)
{
//right paddle
if(key == 1005)
{
rpaddle_up = false;
}
if(key == 1004)
{
rpaddle_down = false;
}
//left paddle
if(key == 115)
{
lpaddle_up= false;
}
if(key == 119)
{
lpaddle_down=false;
}
return true;
}
}[/code]
All I need now is something that tells the paddles what to do once rpaddle_up is true and lpaddle_down is true, etc. Where should I put that and what should it say?[/QUOTE]
You should probably put that in your game loop. Make it move the current active block on the X axis by a specific amount.
[QUOTE=Donkie;39970462]You should probably put that in your game loop. Make it move the current active block on the X axis by a specific amount.[/QUOTE]
I've got the movement down, I just need to know where to put it. How do I write a game loop?
In my games, I have a function called update(), and one called paint(), the update one does all the game logic, and calls the paint() function. In main() I have a while (running = true) which calls update. You could also call paint() in main after you call update()
What the heck is going on?
I have an array of points and I'm trying to draw a mesh in processing using TRIANGLE_STRIP, thing is it looks like all the shapes are staying, or something weird is going on.
[img]http://puu.sh/2kEHJ/1cab992561[/img]
[QUOTE=Zethereal;39956926]Okay, so how would I go about adding stuff up in a row in a CSV file and appending that to the end of the row, then doing that for every row available using C?[/QUOTE]
Your choices for writing to a file in C are either appending to the end of a file or overwriting its contents. That means you need to do it in two passes. Pseudocode:
[code]open file for reading
read entire file into a string (you could also do some parsing here if you want)
close file
open file for writing
for each line in stored string
parse line to get total
print the line
print the total
end for
close file
[/code]
That's the quick-n-dirty approach. One downside is that if you have an error in your CSV file, this program will erase the whole thing! To do it properly, you would want to parse the whole file on the first pass and make sure you can calculate all of the sums safely, then open the file for writing.
Any of you guys know XNA? Right now I know how to draw a textured primitive using BasicEffect. However, any idea how to make it use my own effect (i.e shader?)
What's the hang out spot for all the hardcore java programmers? Can't seem to find a good forum.
My background experience is in C. I'm studying computer science in college. I have some basic experience in Java, but the language I know best so far is C. So, on to my query:
I Want to make a program that yanks the audio from youtube and saves it as an MP3 and various other audio formats. Now, you might be thinking this is to advanced for me. I want to jump right into this and have something to work on. If someone could outline an algorithm I could follow, methods I need to implement, etc.. I WILL figure it out. Right now I just don't know where to begin
[QUOTE=account;39950840][cpp]FILE *file;
int main(int argc, char **argv) {
[/cpp]
main() takes these arguments which are the count of arguments and an array of strings. It doesn't take a FILE *. That said, you could just do int main(void) since you're not using any command-line arguments.
[cpp]while(n = fscanf(file, "%s", temp) != EOF || n > 0){
fscanf(file, "%s", temp);
[/cpp]Get rid of the second fscanf - you've already done the scan in the while(n = fscanf(.... part
Also, I think you can use fgets() to read line-by-line.
[cpp]fgets(temp, MAX_CHARS, file);[/cpp]
It'll read until it either sees a newline or reads MAX_CHARS characters.
[cpp]
if(atof(temp) == 0){
cuewords[counter][sizeof(temp)] = temp;
counter++;
}
else{
numerals[counter][sizeof(temp)] = atof(temp);
counter++;
}
}
}
[/cpp]
I'm not sure what you're doing here - but sizeof(temp) is not what you want. It gives the size of temp as a pointer, which is either 4 or 8, always. If you want the string length of temp, use strlen(temp). You're also setting a char to a char * in the first assignment: cuewords[counter][sizeof(temp)] is a char. You just want to set cuewords[counter] to temp.[/QUOTE]
Thank you kind sir, very thorough
If I've recently started in C++ and want along term project to commit to would it be wise to create my own mashed up game engine and then work from there or use one already acailable to me?
[QUOTE=RandomDexter;39947384]I started something but i crashes, nothing new -.-
[code]FILE *file;
int main(FILE *file){
char cuewords [1000][99];
double numerals [1000][99];
char temp[99];
int counter;
file = fopen ("File000.txt", "rt");
int n;
while(n = fscanf(file, "%s", temp) != EOF || n > 0){
fscanf(file, "%s", temp);
if(atof(temp) == 0){
cuewords[counter][sizeof(temp)] = temp;
counter++;
}
else{
numerals[counter][sizeof(temp)] = atof(temp);
counter++;
}
}
}
[/code]
Now, how do i scan lines separately?[/QUOTE]
If you want to scan lines separately, you need to use fgets. Note though, fgets keeps the '\n' operator. If you're reading in strings and want to do it properly, you should use fgets and then from there dynamically store it into a data structure. Choose the data structure that's appropriate for your task (not sure what you're trying to do). Odds are you don't need those doubly sub-scripted arrays. I think you're using the wrong data structure for the task at hand. Also, you never close your file, which means you have a memory leak. You need to use fclose(file000.txt);
Quick C# question
I have VS2012, and working with a MySQL DB. I have all the connections and everything, now I just need to find one thing. I had it, but Visual Studio decided to hide it again. It is the control where you can take a table from the DB, and drag it into the form, as either a table adapter or binded textboxes / lables, and adds all the necessary table adapters, binding sources etc. Do any of you know where the hell M$ hides it?
I have to encode and decode a binary tree in which I have been trying to do for 3 days now. I have finally hit the point where I must ask for help in which I really hate doing but I cannot figure this out.
I'm really bad with binary tree's... mainly because I find them completely useless... Anyone able to help me out?
[CODE]
<Due to size>
http://pastebin.com/tTbX5jng
[/CODE]
Sorry, you need to Log In to post a reply to this thread.