Cocoa Touch: Trouble populating 2D array
I am writing an app that uses SQLITE3. I am populating array with a value located in a double-dimensioned array (matrix). When I do this, I am getting an ASSERTION error and I cannot figure out why:
ViewController.h
matrix1 [25][1000];
array1 [2000];
ViewController.m
Populating array1 at index matrix[i][j], with the value in matrix1[i][j]
for(int i = 0; i<1000; i++){
for(int j = 0;j<25; j++)
{
array1[matrix1[开发者_JAVA技巧matrix1[i][j]];
}
}
...
if(sqlite3_exec(pb_database,[pb_update_string UTF8String]
,NULL,NULL,&errormsg)!= SQLITE_OK) {
NSAssert1(0, @"Error updating tables: ==> %s <==", errormsg);
sqlite3_free(errormsg);
NSLog(@"line not update");
}
The error is always on the INSERT/REPLACE statement.
You have several problems:
- You're using the SQLite C API directly. Don't do this unless you have a very good reason. Use FMDB instead. It will make your life much easier.
- Your arrays are not the same size. One contains 25,000 elements (25*1000), and the other contains 2,000 elements.
- Your
for
loop does nothing.array1[matrix1[matrix1[i][j]];
is not only syntactically incorrect (you're missing a closing square bracket), but it doesn't do anything. - Your SQLite code has absolutely nothing to do with your
for
loop.
精彩评论