[QUOTE=Gulen;39864019]What do you mean it scans the empty spaces?[/QUOTE]
i doesn't scan right. I'm trying to make the program read char and then convert it in int according to the rule where a->0 b->1 c->2 ... '-'->27. when i write for example "cnxqp" the output should be "2,13,23,16,15", but i get "1988126848 2 13 23 16" instead
The rest of my code, where i convert
[code]
char testsubject202 [lenghtofseq];
char alphabet[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','-'};
int Converter [lenghtofseq];
for(int i = 0; i < lenghtofseq; i++){
for(int j = 0; j < 28; j++){
if(testsubject202[i] == alphabet[j]){
Converter[i]=j;
}
}
}
[/code]
I don't see how it'd output what it does in that code, could you post more? Specifically where you print it? Or where you modify the Converter, if you do?
How would I go about creating a layout editor/visual builder, are there any nice libraries I could use also apart from swing?
Which language are you looking for?
Java
[QUOTE=Gulen;39864515]I don't see how it'd output what it does in that code, could you post more? Specifically where you print it? Or where you modify the Converter, if you do?[/QUOTE]
here's the whole deal
[code]
printf ("Insert the sequence of chars(from 'a' to '-'): ");
for(int i = 0; i < lenghtofseq; i++){
testsubject202[i] =getchar();
}
char testsubject202 [lenghtofseq];
char alphabet[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','-'};
int Converter [lenghtofseq];
for(int i = 0; i < lenghtofseq; i++){
for(int j = 0; j < 27; j++){
if(testsubject202[i] == alphabet[j]){
Converter[i]=j;
}
}
}[/code]
So you're trying to take a sequence of characters in a..z as well as '_' and '-' and convert it to letters where a = 0?
[cpp]#include <stdio.h>
static int convert(char x)
{
if (x <= 'z' && x >= 'a')
return (x - 'a');
else if (x == '_')
return 26;
else if (x == '-')
return 27;
return 28;
}
int main(void)
{
int lengthofseq = 10;
int i;
int testsubject202[10];
for (i = 0; i < lengthofseq; i++) {
testsubject202[i] = convert(getchar());
printf("Got %d\n", testsubject202[i]);
}
}[/cpp]
This is the gist of it, I think
[cpp]
static int convert(char x)
{
if (x <= 'z' && x >= 'a')
return (x - 'a');
else if (x == '_')
return 26;
else if (x == '-')
return 27;
return 28;
}
[/cpp]
How's this works? Never seen something like that o.o
[QUOTE=mobrockers2;39865360][cpp]
static int convert(char x)
{
if (x <= 'z' && x >= 'a')
return (x - 'a');
else if (x == '_')
return 26;
else if (x == '-')
return 27;
return 28;
}
[/cpp]
How's this works? Never seen something like that o.o[/QUOTE]
Do you understand that the (unsigned) char type is just a number from 0 to 255? And that letters and numbers in ASCII are contiguous?
[QUOTE=Rayjingstorm;39865399]Do you understand that the (unsigned) char type is just a number from 0 to 255? And that letters and numbers in ASCII are contiguous?[/QUOTE]
Well I do now.
[QUOTE=account;39865264]So you're trying to take a sequence of characters in a..z as well as '_' and '-' and convert it to letters where a = 0?
[cpp]#include <stdio.h>
static int convert(char x)
{
if (x <= 'z' && x >= 'a')
return (x - 'a');
else if (x == '_')
return 26;
else if (x == '-')
return 27;
return 28;
}
[/cpp]
[/QUOTE]
I dont really get this. The only problem in my code is, that the last char in sequence isn't converted and that the first number is some gibberish
[QUOTE=RandomDexter;39865504]I dont really get this. The only problem in my code is, that the last char in sequence isn't converted and that the first number is some gibberish[/QUOTE]
His code is much shorter and better structured.
Solved it, finally.
[QUOTE=RandomDexter;39865504]I dont really get this. The only problem in my code is, that the last char in sequence isn't converted and that the first number is some gibberish[/QUOTE]
Well this function just takes a character, x, and returns a number from 0 to 27 (28 on an illegal character) that corresponds to its position in your sequence. so convert('a') returns 0, convert('b') 1, and all the way to convert('-'), which returns 27. By putting the result of this in your int array, you get the number sequence you're looking for. And in my opinion, it's shorter and uses fewer loops which is usually a good thing.
I'm learning OpenGL (ES 2.0) and I'm having a really hard time dealing with matrices. More specifically, I don't get the behavior I'd expect when scaling the model matrix.
This is what my line looks like when I just use the identify matrix to render a line from 0,0,0 to 1,1,1:
[img]http://puu.sh/2ftKh[/img]
This is what it looks like when I scale it like this:
[img]http://puu.sh/2ftHc[/img] (using [url=http://developer.android.com/reference/android/opengl/Matrix.html]Android's Matrix class[/url])
[img]http://puu.sh/2ftGr[/img]
I'd expect it to be 70% of the previous length, but it's obviously much shorter. What's happening here? Translation works perfectly fine I think.
[QUOTE=Robber;39867696]I'm learning OpenGL (ES 2.0) and I'm having a really hard time dealing with matrices. More specifically, I don't get the behavior I'd expect when scaling the model matrix.
This is what my line looks like when I just use the identify matrix to render a line from 0,0,0 to 1,1,1:
[img]http://puu.sh/2ftKh[/img]
This is what it looks like when I scale it like this:
[img]http://puu.sh/2ftHc[/img] (using [url=http://developer.android.com/reference/android/opengl/Matrix.html]Android's Matrix class[/url])
[img]http://puu.sh/2ftGr[/img]
I'd expect it to be 70% of the previous length, but it's obviously much shorter. What's happening here? Translation works perfectly fine I think.[/QUOTE]
You're multiplying the size by .7*.7, not by .7
[editline]10th March 2013[/editline]
Possibly even .7*.7*.7
[editline]10th March 2013[/editline]
Though I still don't understand why it'd be [I]that[/I] small
So I fixed the problems I had.
now have one main question. looping through an array to search is easy, but how would i loop through two arrays, searching one for the contents of another
(find all prime numbers that are not fibonacci numbers)
I tried a 3 nested for loop, with the outer one rotating through the primes, the middle through the fibs, and the inner to fill the array with the matches, but that just infinite looped
[QUOTE=LordCrypto;39871347]So I fixed the problems I had.
now have one main question. looping through an array to search is easy, but how would i loop through two arrays, searching one for the contents of another
(find all prime numbers that are not fibonacci numbers)
I tried a 3 nested for loop, with the outer one rotating through the primes, the middle through the fibs, and the inner to fill the array with the matches, but that just infinite looped[/QUOTE]
Post the code please.
[QUOTE=LordCrypto;39871347]So I fixed the problems I had.
now have one main question. looping through an array to search is easy, but how would i loop through two arrays, searching one for the contents of another
(find all prime numbers that are not fibonacci numbers)
I tried a 3 nested for loop, with the outer one rotating through the primes, the middle through the fibs, and the inner to fill the array with the matches, but that just infinite looped[/QUOTE]
You shouldn't need three loops, I don't think. I would also loop through the fibonacci's in the outer loop and the primes in the inner, since you want to test whether each fib is equal to any of the primes. Something like this?
[cpp]int i, j, k, composite;
k = 0;
for (i = 0; i < NUM_FIBS; i++) {
composite = 1; // assume it's composite at first
for (j = 0; j < NUM_PRIMES; j++) {
if (fibs[i] < primes[j])
break; // next fib once the primes are bigger
if (fibs[i] == primes[j]) {
composite = 0; // if it's one of the primes, it's not composite
break;
}
}
if (composite)
compositefibs[k++] = fibs[i];
}
[/cpp]
Do the outer two nested loops like you said, then just keep a counter, k, of the number of matches we've found.
Basically it has to record the ones that are primes but not fib's, and load them into a third array. I figured rotating through each array would work. Unfortunately, it would infinite loop. Thankfully, for the two other arrays I have to populate, I can just reverse the logic/order of the primes and the fibs, so I only have to figure out one.
[cpp]int getprimes_nfibos (int primes [], int fibos [], int primesNFibos [], int pSize, int fSize, int limit)
{
int pNFSize = 0;
int dummySearch;
for (int i = 0; i < pSize; i++)
{
dummySearch = primes[i];
cout << "dummysearch\n";
for (int ii = 0; ii < fSize; i++)
{
cout << "inside for2\n";
for (int iii = 0; iii < pSize ; iii++)
{
cout << "inside for3\n";
if (!(dummySearch == fibos[ii]))
{
cout << "inside if\n";
primesNFibos[iii] = dummySearch;
pNFSize++;
break;
}
else
iii--;
}
}
}
return pNFSize;
}[/cpp]
full code: [url]http://pastebin.com/8GNsvHmn[/url]
[QUOTE=LordCrypto;39872293]Basically it has to record the ones that are primes but not fib's, and load them into a third array. I figured rotating through each array would work. Unfortunately, it would infinite loop. Thankfully, for the two other arrays I have to populate, I can just reverse the logic/order of the primes and the fibs, so I only have to figure out one.
[/QUOTE]
As soon as the if statement returns false it would do an infinite loop. You're moving back a position in the loop yourself, making it to redo that position constantly.
Something like this happens (using example values):
[code]
iii=4
if(!dummysearch==fibos[ii]) = false
iii=3
iii=4
if(!dummysearch==fibos[ii]) = false
iii=3
iii=4
...
[/code]
This is repeated forever.
I can't for the life of me understand why you need to nest three loops.
Make a counter variable outside the loops. Starting at 0
First loop goes through the primes, second loop goes through the fibs.
Compare current prime with current fib.
If not a match (that's what you're checking for), add it to the primesNFibos array and increment the counter value.
You should be careful with nesting for loops, as it makes the computational time rise exponentially. Always try to avoid it if you can (I'm not saying never to use them. There are many circumstances were it can't be helped. But it shouldn't be used if it can be avoided in an elegant way).
Last note. You can check if something isn't a match by using the "is not" operator:
if ((dummySearch != fibos[ii]))
instead of:
if (!(dummySearch == fibos[ii]))
Doesn't really matter, it's just aesthetics really as they achieve the same thing. And a good compiler would most likely optimize it correctly anyways.
Hey, I am making an android app and this is first time I am required to use and learn SQLite.
I was following some crap tutorial which lead me nowhere and I ended up having this file:
[code]package com.example.droid;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class SqDb extends SQLiteOpenHelper{
private static final String NAME = SqDb.class.getSimpleName();
public static final String dName = "ExpenseR.db";
public static final int dVer = 1;
public static final String table = "Expenses";
public static final String sql = "create table user_data (" +
"_id INT PRIMARY KEY AUTOINCREMENT, " +
"_typ VARCHAR(20)," +
"_desc VARCHAR(255)," +
"_day INT(2)," +
"_mon INT(2)," +
"_cat VARCHAR(25)," +
"_val REAL," +
"_time TIMESTAMP);";
public SqDb(Context context) {
super(context, dName, null, dVer);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
[/code]
How do I add/read entries from db from other classes.
[QUOTE=arleitiss;39874623]Hey, I am making an android app and this is first time I am required to use and learn SQLite.
I was following some crap tutorial which lead me nowhere and I ended up having this file:
[code]package com.example.droid;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class SqDb extends SQLiteOpenHelper{
private static final String NAME = SqDb.class.getSimpleName();
public static final String dName = "ExpenseR.db";
public static final int dVer = 1;
public static final String table = "Expenses";
public static final String sql = "create table user_data (" +
"_id INT PRIMARY KEY AUTOINCREMENT, " +
"_typ VARCHAR(20)," +
"_desc VARCHAR(255)," +
"_day INT(2)," +
"_mon INT(2)," +
"_cat VARCHAR(25)," +
"_val REAL," +
"_time TIMESTAMP);";
public SqDb(Context context) {
super(context, dName, null, dVer);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
[/code]
How do I add/read entries from db from other classes.[/QUOTE]
Create a method which takes a string as input and sends that string to your sql server and returns whatever the server returns.
I think you'd need to do something like this, though I personally have never done it.
[QUOTE=mobrockers2;39874676]Create a method which takes a string as input and sends that string to your sql server and returns whatever the server returns.
I think you'd need to do something like this, though I personally have never done it.[/QUOTE]
What do you mean? I don't quite understand. Bit of explanation anyone? I did MySQL before but not SQLite.
I've got an SQL problem, if anyone can help me with it. It's for some work for Uni, been trying to figure it out for over a week and haven't gotten anywhere.
I've got a table with a list of students, containing their names, gender, and date of birth. I need to write a query that shows a list of all the girls who were 14 on or before the 1st September 2008. I've been able to calculate the difference between their date of birth and that date using an alias, but there's no way of using aliases in WHERE clauses. Does anyone know of a solution?
edit - I'm using Oracle by the way.
I'm trying to create a Tic-tac-toe game in C++, however whenever a player places a mark on the last element of each row, it creates a duplicate mark on the next row also. I can't figure it out.
Basically, If you run the program and pick position 3, it will output
- - X
X - -
- - -
[CODE]#include <iostream>
using namespace std;
char Board[2][2];
int player = 1;
int run = 2;
void Initboard()
{
int i;
int z;
for(i=0;i<3;i++)
{
cout << "\n\n";
for(z=0;z<3;z++)
{
Board[i][z] = '-';
cout << "||" << " " << Board[i][z] << " ";
if(z == 2)
cout << "||";
}
}
cout << "\n";
}
void changeBoard(int position)
{
int row = position / 3;
int column = position % 3;
if((player == 1 & run == 1) || (player == 0 && run == 0))
Board[position / 3][position % 3] = 'X';
else
Board[row][column] = 'O';
}
void displayBoard()
{
int i;
int z;
for(i=0;i<3;i++)
{
cout << "\n\n";
for(z=0;z<3;z++)
{
cout << "||" << " " << Board[i][z] << " ";
if(z == 2)
cout << "||";
}
}
cout << "\n";
}
int promptPlayer(int player)
{
int choice = 0;
if ((player == 1 & run == 1) || (player == 0 && run == 0))
{
cout << "Player 1, Which space (1-9) would you like to place an X in?\n";
cin >> choice;
choice = choice - 1;
return choice;
}
else
{
cout << "Player 2, Which space (1-9) would you like to place an O in?\n";
cin >> choice;
choice = choice - 1;
return choice;
}
}
void setPlayer()
{
if(run == 2)
{
cout << "Player 1's Turn\n";
run--;
}
else
{
if (player == 1 && run == 1)
{
run--;
cout << "Player 2's Turn\n";
}
else if(player == 1 && run == 0)
{
cout << "Player 1's Turn\n";
player--;
}
else if(player == 0 && run == 0)
{
cout << "Player 2's Turn\n";
player++;
}
}
}
int main()
{
int active = 1;
Initboard();
while(active == 1)
{
setPlayer();
changeBoard(promptPlayer(player));
displayBoard();
}
system("pause");
return 0;
}
[/CODE]
[QUOTE=esalaka;39867885]You're multiplying the size by .7*.7, not by .7
[editline]10th March 2013[/editline]
Possibly even .7*.7*.7
[editline]10th March 2013[/editline]
Though I still don't understand why it'd be [I]that[/I] small[/QUOTE]
But why? Shouldn't something like 1,1,0 just set the z coordinate to zero for instance? By your explanation it would mean that everything would be zero.
[QUOTE=Robber;39877216]But why? Shouldn't something like 1,1,0 just set the z coordinate to zero for instance? By your explanation it would mean that everything would be zero.[/QUOTE]
I actually have no idea of what I was thinking because it makes no sense regardless
Was this scaling
[editline]11th March 2013[/editline]
Oh scaleM scales the [I]matrix[/I]
[editline]11th March 2013[/editline]
Also not everything would be zero but by my explanation one axis would be zero and the volume would be zero, I guess.
The area would stay the same.
I don't even know if you can do that
[QUOTE=Striker26;39877188]I'm trying to create a Tic-tac-toe game in C++, however whenever a player places a mark on the last element of each row, it creates a duplicate mark on the next row also. I can't figure it out.
Basically, If you run the program and pick position 3, it will output
- - X
X - -
- - -
[CODE]
char Board[2][2];
[/CODE][/QUOTE]
[code]char Board[2][2];
[/code]
should be
[code]char Board[3][3];[/code]
[QUOTE=account;39877715][code]char Board[2][2];
[/code]
should be
[code]char Board[3][3];[/code][/QUOTE]
I don't understand though, why would it resort to placing the character on the next row?
Sorry, you need to Log In to post a reply to this thread.