Saturday, July 6, 2013
Gray code incrementing
//Calculate Next State
my_timer_UI32++;
for(i = 0; i < SIZE; i ++){ //Decimal to binary conversion
graycode_I16[SIZE-1-i] = (int)((my_timer_UI32 >> i) & 1);
}
for(i = SIZE-1; i > 0; i --){ //binary to gray code
graycode_I16[i] = graycode_I16[i] ^ graycode_I16[i - 1];
}
My problem with this is that this graycode holds time in milliseconds so inorder to increment this I have to increment the decimal time in ms, then convert to binary, then convert to graycode again and this is taking far more time than I would like. So my question is, would it be possible to increment graycode_I16 to so that it would increment the ms by 1? Hopefully this is detailed enough, if you need more details let me know.
Thanks! - Full Post
C Structure Alignment/Padding
typedef struct dataPoint {
tick * tickData;
struct dataPoint * previousDataPoint;
struct dataPoint * nextDataPoint;
} dataPoint;
Compiling on a 64-bit system with 8-byte words, this structure takes up 24 bytes (3 words) of memory.
24 % 8 = 0 ... - Full Post
&& and || precendance
where i=2, j=3, amd k=5;
acooridng to me, it will be executed left to right and then values of m=1, i=3, j=3 and k=5. but i have seen that precednace of && is more than || , than so how this expression is parenthezed by compiler to execute it ?
as it goes to i++, and since it is non-zero , then it dont need to check after this, so stoped there. (this is what i thought before reading that precdance of && is more than || ). so what is wrong here and where ? thanks alot. - Full Post
Mysterious garbage text and weird space reading!
Another thing, is that while reading a tag, it doesn't seem to want to recognize spaces. For example, <img src="img.png"/> reads as imgsrc="imgpng" instead of img, but only when another tag is beside it on the same line. For example:
<head>
<img src="blah.jpg"/>
</head>
Reads the tagname fine, while
<head><img src="blah.jpg"/></head>
Results in strange output.
Full code:
Main problem code:
/* ReadTagName
* When a tag is detected, finds the name of the tag in the form <name ... - Full Post
How can we solve Sudoku?
This is source code of function which solves sudoku,
function returns 1 if solution exists and 0 if not exist.
In case if solution exists, you have resolution in entry parameter of
this function
You can run this function in function main() eg.
if(sudoku(T)) print(T);
where print(T) is group of printing instructions of all table T and T is matrix
which is declared as int T[9][9];
*/
#include <stdlib.h>
#include <stdio.h>
int sudoku(int S[9][9])
{
int **T;
int W[9];
int nr, ile, i, i1, j, j1, jest, k, L, LL, min, ok, w, wpis;
ok=1;
i=0;
while (i<9 && ok){
j=0;
while (j<9 && ok) {
ok=((S[i][j]>=0) && (S[i][j]<=9));
j++;
}
i++;
}
if (ok){
w=0;
while ((w<9) && ok){
for (i=0;i<9;i++) W[i]=0;
for (j=0;j<9;j++) if (S[w][j]>0) W[S[w][j]-1]++;
j=0;
while (j<9 && ok){
ok=(W[j]<2);
j++;
}
w++;
}
if (ok) {
k=0;
while (k<9 && ok){
for (i=0;i<9;i++) W[i]=0;
for (i=0;i<9;i++) if (S[i][k]>0) W[S[i][k]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
k++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=0;i<3;i++)
for (j=0;j<3;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=0;i<3;i++)
for (j=3;j<6;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=0;i<3;i++)
for (j=6;j<9;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=3;i<6;i++)
for (j=0;j<3;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=3;i<6;i++)
for (j=3;j<6;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=3;i<6;i++)
for (j=6;j<9;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=6;i<9;i++)
for (j=0;j<3;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=6;i<9;i++)
for (j=3;j<6;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
for (i=0;i<9;i++) W[i]=0;
for (i=6;i<9;i++)
for (j=6;j<9;j++) if (S[i][j]>0) W[S[i][j]-1]++;
i=0;
while (i<9 && ok){
ok=(W[i]<2);
i++;
}
if (ok){
ile=0;
T=(int **)malloc(2*sizeof(int *));
for(i=0;i<9;i++)
for(j=0;j<9;j++){
if (S[i][j]==0){
ile++;
T[0]=(int *)realloc(T[0], ile*sizeof(int));
T[1]=(int *)realloc(T[1], ile*sizeof(int));
T[0][ile-1]=i;
T[1][ile-1]=j;
}
}
if (ile>0){
nr=0;
while (nr>-1 && nr<ile){
wpis=0;
min=S[T[0][nr]][T[1][nr]];
S[T[0][nr]][T[1][nr]]=0;
LL=min;
for (L=9;L>min;L--){
jest=0;
j=0;
while (j<9){
if (S[T[0][nr]][j]==L) jest=1;
j++;
}
i=0;
while (i<9){
if (S[i][T[1][nr]]==L) jest=1;
i++;
}
if (T[0][nr]<3) i=0; else{
if (T[0][nr]>2 && T[0][nr]<6) i=3; else i=6;
}
if (T[1][nr]<3) j=0; else {
if (T[1][nr]>2 && T[1][nr]<6) j=3; else j=6;
}
for (i1=i;i1<i+3;i1++)
for (j1=j;j1<j+3;j1++) if (S[i1][j1]==L) jest=1;
if (!jest) LL=L;
}
if (LL>min){
S[T[0][nr]][T[1][nr]]=LL;
wpis=1;
} else
{
S[T[0][nr]][T[1][nr]]=0;
wpis=0;
}
if (wpis) nr++; else nr--;
}
}
ok=(nr>ile-1);
free(T[0]);
free(T[1]);
free(T);
}
}
}
}
}
}
}
}
}
}
}
}
return ok;
}
/*
in function main()
int T[9][9];
... - Full Post
Armstrong Number.
Something wrong with this code ?
#include<stdio.h>
#include<conio.h>
void main()
{
int num,range,temp;
int rem,sum=0;
printf("Enter upper range: ");
scanf("%d", &range);
// Checking is a number is armstrong of not.
printf("Armstrong are:");
for(num=10; num<=range; num++)
{
temp=num;
while(temp>0)
{
rem=temp%10;
sum=sum+(rem*rem*rem);
temp=temp/10;
}
if(num==sum)
{
printf("%d\t",num);
}
}
getch();
}
It is giving following output.
Enter upper range: 2000
Armstrong are:12
Thanx. - Full Post
sizeof operator
void f(int n)
{
char pp[n];
printf("%d\n",sizeof(pp));
}
int main()
{
int n;
scanf("%d",&n);
f(n);
}
In this program the size of array is defined at runtime,and sizeof operator is printing correct size after runtime initialisation in gcc 4.4. Can anybody explain? we say that sizeof is compile time operator.then ? and C99 give us to have this type of initaliazation. pp[n], it is dynamic.but it is still working ? (above snippet is working correctly in .cpp and .c both correcttly.) thanks alot. - Full Post
Spiral Matrix
Like this
initial Value = 4
final Value = 18
4 5 6
14 15 16 7
13 18 17 8
12 11 10 9
Code:
#include < stdio.h >
#include < conio.h >
void main()
{
int m[20][20],i,j;
int lc,hc,lr,hr,r,c,cnt;
clrscr();
printf("\nEnter r & c :");
scanf("%d %d",&r,&c);
cnt = 1;
lr = 0; lc = 0;
hr = r - 1;
hc = c - 1;
while ( lr <=hr && lc <= hc )
{
i = lr;
for(j=lc;j <= hc;j++)
{
m[i][j] = cnt++;
j = hc;
for(i=lr+1;i<=hr;i++)
{
m[i][j] = cnt++;
if( lr != hr )
{
i = hr;
for(j=hc-1;j>=lc;j--)
m[i][j] = cnt++;
}
if ( lc != hc )
{
j = lc;
for(i=hr-1;i>lr;i--)
m[i][j] = cnt++;
}
}
}
lr++;lc++;
hr--;hc--;
}//while
printf("\nSpirally filled matrix is\n");
for(i=0;i < r;i++)
{
for(j=0;j < c;j++)
{
printf("%4d",m[i][j]);
printf("\n");
}
}
} // main
I have this program but isnt runnig well. Please please help - Full Post
Insert into sparse matrix as linked list
typedef struct node{
int x;
int y;
int value;
struct node* row;
struct node* col;
}node;
typedef struct matrix{
int height;
int width;
node** rowList;
node** colList;
}matrix;
void insert(matrix** M, int row_index, int col_index, int value)
{
node* currNode=(node*)malloc(sizeof(node));
currNode->x=row_index;
currNode->y=col_index;
currNode->value=value;
if ((*M)->rowList[row_index] == NULL) {
currNode->row = NULL;
(*M)->rowList[row_index] = currNode;
}
else if ((*M)->rowList[row_index]->y > col_index) {
currNode->col = (*M)->rowList[row_index];
(*M)->rowList[row_index] = currNode;
}
else if ((*M)->rowList[row_index]->y < col_index) {
node* rowptr = (node*)malloc(sizeof(node));
rowptr = (*M)->rowList[row_index];
while(rowptr->col!=NULL&&rowptr->col->y < col_index)
rowptr=rowptr->col;
currNode->col=rowptr->col;
rowptr->col=currNode;
}
if ((*M)->colList[col_index] == NULL) {
currNode->col = NULL;
(*M)->colList[col_index] = currNode;
}
else
if ((*M)->colList[col_index]->x > row_index) {
currNode->row = (*M)->colList[col_index];
(*M)->colList[col_index] = currNode;
}
}
- Full Post
Works on MinGW, but not on my uni's computer
It = 0 (should be 0.954499)
pn = 0 (should be 18)
Is = 0 (should be 0.954500)
pn = 0 (should be 6)
This is what I came up with (sorry the variables and comments are in portuguese, I'll fix it later after I get home):
integral.h:
#include <stdio.h>
#include <math.h>
#define eps 1.e-6
#define kmax 20
double trapezio(double (*f)(double x), double a, double b, int *n);
double simpson(double (*f)(double x), double a, double b, int *n);
integral.c:
#include "integral.h"
#define xmin -2
#define xmax 2
double f(double x);
int main(){
double It,Is;
int n = 0;
int *pn = NULL;
pn = &n;
It = trapezio(f,xmin,xmax,pn)/sqrt(2*M_PI);
printf("Pelo metodo dos trapezios a integral vale aproximadamente %lf\n", It);
printf("O numero de iteracoes usadas foi %d\n\n",*pn);
*pn = 0;
Is = simpson(f,xmin,xmax,pn)/sqrt(2*M_PI);
printf("Pelo metodo de simpson a integral vale aproximadamente %lf\n", Is);
printf("O numero de iteracoes usadas foi %d\n",*pn);
return 0;
}
double f(double x){
return exp(-0.5*x*x); // Funcao que sera integrada
}
trapezio.c:
#include "integral.h"
double trapezio(double (*f)(double x), double a, double b, int *n){
double To, Tk;
double soma;
int i, k = 1;
Tk = 0.5*(f(a) - f(b))*(b - a);
while (fabs((Tk-To)/To) > eps && k < kmax){
soma = 0; // Resetando variavel soma
To = Tk; // To e' T(k - 1), caso o loop se repita o ultimo Tk vira To
for (i = 1 ; i <= (pow(2,k)-1) ; i += 2) soma += f(a + i*(b - a)/pow(2.,k));
Tk = 0.5*To + soma*(b - a)/pow(2.,k);
k++;
*n += 1;
}
return Tk;
}
simpson.c:
#include "integral.h"
double simpson(double (*f)(double x), double a, double b, int *n){
double So, Sk = 0;
double somaimp, somapar;
int i, k = 1;
while (fabs((Sk-So)/So) > eps && k < kmax){
somaimp = 0;
somapar = 0;
So = Sk; // So e' S(k - 1)
for (i = 1; i <= (pow(2,k)-1); i += 2) somaimp += f(a + i*(b - a)/pow(2.,k));
for (i = 2; i <= (pow(2,k)-2); i += 2) somapar += f(a + i*(b - a)/pow(2.,k));
Sk = (b - a)*(f(a) + 4*somaimp + 2*somapar + f(b))/(3*pow(2.,k));
k++;
*n += 1;
}
return Sk;
}
Edit: I forgot to mention that if I take the pointer out, trapezio works, but simpson still returns 0. - Full Post
Switch Default Error
It is printing the error message but at end of message is giving a decimal value for the char sign.
How do I stop this from happening?
#include <stdio.h>
char sign;
int x, y;
int main() {
printf("Choose:\n");
printf("a) Addition\n");
printf("b) Subtraction\n");
printf("c) Division\n");
printf("d) Multiplication\n");
scanf("%c", &sign);
sign = 'f'; // For testing the Default
printf("Enter two numbers:\n");
scanf("%d%d", &x, &y);
x = 12; // Test for x
y = 4; // Test for y
/*Print out their numbers inside the math_function*/
printf("%d\n", math_function(x, y));
return 0;
}
int math_function(int x, int y) {
switch(sign) {
case 'a':
return x + y;
case 'b':
return x - y;
case 'c':
return x / y;
case 'd':
return x * y;
default:
printf("'%c' is an invalid choice ", sign);
}
return 0;
}
- Full Post
Stuck Need ! NOOb here
that does this v
A permutation is one of several possible ways in which you can order or arrange a group of things. Write a program that displays a new random permutation of the integers 0 to 9 at the request of its user. For example, the program’s output could be as follows:
1237894560
Another permutation? yes
65310974280
Another permutation? no
Bye!
Your program should prints how many 7 was printed when user type no.
I got only up to here
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char ch;
srand(time(NULL));
do{
printf("%d\n", rand());
if(i=7)
printf("would you like to print again Yes OR No:");
fflush(stdin);
scanf("%c",&ch);
printf("====>>>%c\n",ch);
}while ( ch=='Y' || ch=='y');
printf("Bye!\n");
return 0;
Help my solve this :) - Full Post
need help !! im just beginner .. need answer asap
Write a prgram that ask the user to enter the radius of a circle and then computer for its area where AREA = Pi x R2
Create a program that converts a farenheit measure to a celsius measure (C=5/9 x (F-32)).
Make a program that will compute the two input values considered that the two inputs are s1 and s2 = Ts
Create a program that will input a number in kilowatt and display its equivalent measure in watts
- Full Post
pointer const
void fun(const int **);
int main()
{
int **p;
fun(p);
}
code 2:
void fun(const int **);
int main()
{
const int **p;
fun(p);
}
code 1 is compile error and 2 is not. can you explain why ? as per my knowledge, we can convert a non-const to const but we cant change const to non-const. and even to prove this, when i repace the above with "pointer to int" and everything remain same, then it works. then what is hidden in double pointer conversion fron int ** to const int **. thanks in advance. - Full Post
How to show yes/no value in DataGridViewCheckBoxColumn
I have 7 columns of yes/no data type I want to show them in datagridview in checkbox form. I have written this code where I am showing some values from database to datagridview with a column having check box. I just want to show databse value in Under Sun,Mon,Tue,Wed,Thr,Fri,Sat columns Please refer the code
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
int no_of_branch=0;
int batch_count;
int totalbatch = 0;
foreach (var checkBoxSele in grpBox1.Controls.OfType<CheckBox>().OrderBy(m => m.Name))
{
no_of_branch++;
}
string[] str = new string[no_of_branch];
no_of_branch=0;
foreach (var checkBoxSele in grpBox1.Controls.OfType<CheckBox>().OrderBy(m => m.Name))
{
if (checkBoxSele.Checked)
{
str[no_of_branch] = checkBoxSele.Text;
MessageBox.Show(str[no_of_branch]);
no_of_branch++;
}
}
for (int j = 0; j < no_of_branch; j++)
{
try
{
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str[j] + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
batch_count = ds3.Tables[0].Rows.Count;
dataGridView1.ColumnCount = 11;
dataGridView1.Columns[0].Name = "Batch Code";
dataGridView1.Columns[1].Name = "Centre";
dataGridView1.Columns[2].Name = "Duration";
dataGridView1.Columns[3].Name = "Time";
dataGridView1.Columns[4].Name = "Sun";
dataGridView1.Columns[5].Name = "Mon";
dataGridView1.Columns[6].Name = "Tue";
dataGridView1.Columns[7].Name = "Wed";
dataGridView1.Columns[8].Name = "Thr";
dataGridView1.Columns[9].Name = "Fri";
dataGridView1.Columns[10].Name = "Sat";
for (int k = 0; k < batch_count; k++)
{
string exisBatch = ds3.Tables[0].Rows[k][0].ToString();
int batlen = exisBatch.Length;
string dur = ds3.Tables[0].Rows[k][16].ToString();
DateTime vtime = DateTime.Parse("16:00");
switch (dur)
{
case "Mor": vtime = DateTime.Parse("08:00");
break;
case "Eve": vtime = DateTime.Parse("16:00");
break;
}
shortBCode = ds3.Tables[0].Rows[k][1].ToString() + ds3.Tables[0].Rows[k][15].ToString() + ds3.Tables[0].Rows[k][16].ToString().Substring(0, 1) + exisBatch.Substring(batlen - 3);
dataGridView1.Rows.Add(shortBCode,
ds3.Tables[0].Rows[k][2].ToString(),
ds3.Tables[0].Rows[k][10].ToString(),
vtime.ToString("HH:mm"),
ds3.Tables[0].Rows[k][7].ToString());
//comboBox2.Items.Add(ds3.Tables[0].Rows[i][0].ToString());
totalbatch++;
}
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].ReadOnly = true;
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(chk);
chk.HeaderText = "Freeze";
chk.Name = "chk";
label3.Text = totalbatch.ToString();
}
catch (OleDbException ex)
{
MessageBox.Show("Please close the Databse");
}
}
}
- Full Post
Turn off Visual Styles on the design surface?
Is there a way to disable visual styles on the design surface? I can't seem to figure it out. The closest I got was changing the OS theme.
Seems kinda silly to try to design an application without Visual Styles and be forced to do it with visual styles enabled on your design surface. Kinda like trying to draw a picture using just a sheet of carbon paper and not seeing what your drawing looks like for real, just a idea. - Full Post
Fibonacci in C#
Most famous for his series, but who among you all, know that he was the man who introduced to the Western world, the Arabic numeral system(including zero) in 1202 A.D.? The Italian merchands of those days adored it. It was far more easy to work with than the roman numeral system of course. And it is still in use today.
I did the series a little different with a calculation that gives you any Fibonacci number from zero up to the 93th one. I guess the Convert method does the rounding. Also included here in the code, is a little test loop.
Enjoy! - Full Post
Looping through datagrid cells
string CellVal = null;
int Rowcount = 0;
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataGrid1.DataSource];
int rowCount = cm.Count;
int colCount = ((DataTable)this.dataGrid1.DataSource).Columns.Count;
for (int row = 0; row < rowCount; row++)
{
for (int col = 0; col < colCount; col++)
{
CellVal = this.dataGrid1[row, col].ToString();
}
}
- Full Post
How to compare cell values of datagridview with each other
Detail:
I need to compare 1st Row cell value with rest of the 6 rows cell values, same thing repeats for 2nd Row for rest 5 row, again same comparison needed for 3rd row with rest 4 rows. Basically It is row wise comparison
ROW1-> 2 2 2 4 4 6 6 8 8 8 7 7
ROW2-> 1 1 1 7 7 7 6 9 9 9 7 7
ROW3-> 1 1 3 3 3 3 5 5 5 0 0 0
ROW4-> 2 2 2 0 0 0 0 1 1 1 7 7
ROW5-> 0 0 0 3 3 3 4 4 4 8 8 8
Now I want to color those Cell whose values are repeating. Any idea will be a great help for me.
Here is the code
public void check_conflict()
{
int rowCount=dataGridView1.RowCount;
int colCount=dataGridView1.ColumnCount;
string val1;
int c = 1;
for (int k = 0; k < rowCount - 1; k++)
{
for (int i = 1; i < colCount; i++, c++)
{
val1 = Convert.ToString(dataGridView1.Rows[k].Cells[i].Value);
for (int j = 1; j < rowCount - 1; j++)
{
string val2 = Convert.ToString(dataGridView1.Rows[j].Cells[i].Value);
if (val1 == val2 && (val1 != "" && val2 != ""))
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Red;
dataGridView1.Rows[j].Cells[i].Style = CellStyle;
}
}
}
}
}
Problem I facing with code is it is only comparing 1 Row with others - Full Post
String.Contains Possible Bug?
I have built countless programs around downloading webpage data and parsing it to retrieve data, but during a running of one of my programs tonight I got an error message. Well the error message happened due to a value equaling -1. Now I didn't put a check in there because that value should never equal -1.
But then I realized that my program had an issue. I have an if statement that contains a String.Contains check. The check triggered true, DESPITE the fact that the string I was checking for did not even remotely existing in the other string.
See, I even have a picture of the flaw (with some shotty photoshop work)
So can someone help me out here. Did I just stumble on a bug, is this a known problem when using String.Contain or what cause right now this has me scratching head - Full Post
edit not reading all rows
{
if (!Page.IsPostBack)
{
sqlcon.Open();
sqlcmd = new SqlCommand("select * from category" , sqlcon);
da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox4.Text = dt.Rows[0][7].ToString();
TextBox2.Text = dt.Rows[0][8].ToString();
TextBox3.Text = dt.Rows[0][9].ToString();
}
sqlcon.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
sqlcmd = new SqlCommand("update category set invcategorycode='" + TextBox2.Text + "',invcategorydesc='" + TextBox3.Text + "' where invcategorydescar='", sqlcon);
sqlcmd.Parameters.AddWithValue("@invcategorycode", TextBox4.Text);
sqlcmd.Parameters.AddWithValue("@invcategorydesc", TextBox2.Text);
sqlcmd.Parameters.AddWithValue("@invcategorydescar", TextBox3.Text);
sqlcon.Open();
sqlcmd = new SqlCommand();
sqlcmd.ExecuteNonQuery();
int result= cmd.ExecuteNonQuery();
if (result == 1);
sqlcon.Close();
}
protected void LinkButton11_Click(object sender, EventArgs e)
{
Response.Redirect("Category.aspx");
}
}
in this code only information of the first row is read to all the rows
and am getting an error in ExecuteNonQuery();
how can i get each edit next to a row to read its information? - Full Post
Problem with Microsoft C# Tutorial #2
I'm following tutorial and I'm encountering strange behaviour with the program.
My finishLabel ought to be calling finishLabel_MouseEnter() when the mouse hovers over it, but it's calling wall_MouseEnter() instead - the location of the mouse resets and the congratulations box doesn't show up. In the properties/events box for the label, finishLabel_MouseEvent is selected. In Form1.Designer.cs,
`// `
`// finishLabel`
`// `
`this.finishLabel.AutoSize = true;`
`this.finishLabel.Location = new System.Drawing.Point(467, 430);`
`this.finishLabel.Name = "finishLabel";`
`this.finishLabel.Size = new System.Drawing.Size(34, 13);`
`this.finishLabel.TabIndex = 15;`
`this.finishLabel.Text = "Finish";`
`this.finishLabel.MouseEnter += new System.EventHandler(this.finishLabel_MouseEnter);`
describes my finishLabel, and there are no other 'this.finishLabel.MouseEnter' lines.
In Form1.cs,
`private void finishLabel_MouseEnter(object sender, EventArgs e)`
` {`
` // Show a congratulatory MessageBox, then close the form.`
` MessageBox.Show("Congratulations!");`
` Close();`
` }`
describes how the method should be working.
I tried changing the event box selection back and forth between the two available events, and restarting the IDE (Visual Studio 2012 Express for Desktop) in case it was an error there, but regardless of how I run the program the finishLabel behaves incorrectly.
Any ideas on what the problem might be?
Thanks in advance,
Devon - Full Post
Searching and Opening Files
Im want to create a program for myself which will search my directories for ebooks and let me select the one i want to read. So for instance my first form has a button for C# Books, I want that then to produce a list of books found on my computer and let me pick one to read.
I know a way i can do this using oledb and msaccess and having a link field in the table. However the purpose is I do not wish to do this everytime I attain a new book.
no code snippets as of yet as i've just started the program
If anyone knows a way or can point me in the right direction, would appreciate it very much.
Cheers Guys. - Full Post
Application Exit
I have a MDI application that when run for the first time it asks for the activation code by showing the main Windows Form (MDI parent) and another activation acquire code Windows Form showed above the main Windows Form using the ShowDialog() method. The main Windows Form including a tool strip button when I exit the activation Windows Form by clicking the X upper right corner button, that tool strip is disabled and I cannot use it to exit the application and when I click the X upper right corner button of the main Windows Form to exit the application it gives me an error Windows report message informing that "vshost-clr2.exe has stopped working" when I looked for the main Windows form FormClosed event I found that line of code
System.Environment.Exit(0)
What is the problem the causing such error "vshost-clr2.exe has stopped working" when clicking the X upper right corner of the main Windows Form (the MDI parent) - Full Post
Implementing Java's "Exceptions Thrown by a Method" in C#
public boolean isRequest() throws NullPointerException
{
// blocks of code implementing isRequest() method;
}
For the C# implementation of this code snippet, I searched the web and quite shockingly found that, C# does not support throwing exceptions in the compile time.
Now my question is, how can I implement this code portion in a C# library? - Full Post
Linq time searching
My asp page refreshes and displays the new information that was updated.
What I want is to have it so when a row has not been updated in 5 minutes that it turns the textbox red. I know how to do the change the textbox but I do not know how to search if a row was updated in the last 5 minutes or not. I do not want it to check if the textbox has changed or not becuase we use a lot of the same numbers and will read it as not changing.
This is what I have.
var RedLine4Sc1 = (from l in ***.***
where l.**_Port == 4 && l.**_Port == 1 && l.***_Number == 1 && l.Date_Processed >= startDateTime
select l.Date_Processed);
I know this is not correct because it is just seeing if the processed date is == to the time and I was just messing aorund with stuff.
Just tried this because figured it might be better but getting an error. Think it is because it does not see the datetime.
if (Convert.ToDateTime(RedLine4Sc1) >= redDateTime)
Any help would be appriciative.
Thanks. - Full Post
C# Linq To SQL get new inserted data (Tracking)
For an example:
If the database gets a new insert value from another application that I currently have: then
My other application will notice it and fetch that data instead of getting the whole table each time.
Currently I have a loop that just gets the whole table each second. But I need to fetch the last change of the database. Is this possible or do I have to use a trigger in the database? Because I need to fix this without the use of a trigger.
(I only need the new change from the table, inserts, deletion & updates)
Thanks - Full Post
LINQ and MariaDB
"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[t0].[Id], [t0].[BirthYear], [t0].[FirstName], [t0].[Gender], [t0].[LastName], [' at line 1"
The table in MariaDB is setup the same as it was in MS SQL.
Any thoughts on this subject would be most appreciated. I could go back and remove all use of LINQ and write SQL by hand, but if I can get it to work as is it will save a great deal of time, and therefore money.
Thanks in advance. - Full Post
C# Sysmon/Perfmon Help
I am totally new to this, so I realy need some good tutorial or any help.
Thanks. - Full Post
On the fly compiling of dll
Parden me if I do not express my question very well.
A project I am considering would benefit greatly from the ability to to compile a dll at runtime, on machines which may or may not have appropriate tools installed (so I may be looking at using third party tools if available)
For example, User runs my executable, which creates a dll with a function they want to use, selected by them.
My executable adds the function(s) and compiles a dll and outputs a usage txt file.
My questions are: is there some sort of tool/portalbe app I could use to accomplish this? is there a proper name or term for what I am trying to accomplish?
Any tips or comments are very welcome. - Full Post
Two Dimensional Dice Array
Die 1
1 2 3 4 5 6
1
D 2
I 3
E 4 Results
2 5
6
My code just prints the combinations going down as so
result
result
result
etc... - Full Post
Building C++ Programs from Command Line?
Often when I ask questions on forums they give me a command line solution for compiling projects. Whilst I'm not overly familiar with it I'm wondering what everyone thinks about it. Is it better to send my compiler instructions from the command line or use an IDE to compile. I know that an IDE has it's advantages such as preprogrammed libraries etc.
Any thoughts? Hope my question makes sense. - Full Post
Friday, July 5, 2013
C Programming iOS Development Starts Here! at sCoolTV
https://www.scooltv.com/course/2191/ (I added a video to a @YouTube playlist http://t.co/v9XQuVTB4l C Programming iOS Development Starts Here!- Full Post
Microsoft 70-515 TS: Web Applications Development with .NET Framework 4 (VB & C#) Free Practice Exam
Free Practice Exam to Microsoft 70-515 TS: Web Applications Development with .NET Framework 4 (VB & C#).- Full Post
Astronauts4Hire: Happy Holidays from A4H
Reflecting back upon 2012, I am impressed by the strides Astronauts4Hire has made to firmly establish itself as an important leader in the commercial spaceflight industry. Our primary mission is to build the next generation astronaut workforce by providing skills training, networking, and other professional development opportunities to aspiring commercial astronauts. As a 501(c)(3) educational nonprofit, we rely upon the volunteer efforts of our members, generosity of our sponsors, and collaboration with our partners to meet our goals. With your help, we have achieved a lot in the past year, including:
- Full PostShare your knowledge: Getting Play2.0.x to work with Git Bash on ...
nxp10009@NXL01366 /c/workspaces/scala $ play Error during sbt execution: Could not find configuration file 'c:/development/play-2.0.4/framework/sbt/play.boot.properties'. Searched: file:/c:/workspaces/scala/ ...- Full Post
Category Extending NSString Allowing You To Use FontAwesome Icons In Your Apps
Featured iPhone Development Resources,iOS Development Libraries,Objective-C,Open Source iOS Libraries And Tools There are many sources for free icons around, but here’s a project that allows you to do something different with icons by allowing...- Full Post
Nathan Heller: Is College Moving Online?
Many people think that MOOCsare the future of higher education in America. In the past two years, Harvard, M.I.T., Caltech, and the University of Texas have together pledged tens of millions of dollars to MOOC development. Many other élite schools, from U.C. Berkeley to Princeton, have similarly climbed aboard.
- Full PostOpen Source iOS UITableView Replacement W/Simpler API, Terrific Style, And Blocks Based Events
The Canon EOS-1D C is Different Than the EOS-1D X on the Inside
Posted by Canon Rumors on October 19, 2012
The EOS-1D C isn’t just firmware
"There have been reports around the web that the upcoming Canon EOS-1D C is the exact same camera internally as the EOS-1D X (other than the PC sync port) and Canon is just charging people $7000 for different firmware.
I have spent considerable time trying to find someone at Canon to clarify the reports as well as someone to open their EOS-1D C (no one would do that for me!). The information I have received backs up what Canon said at the development announcement of the EOS-1D C, it does in fact have a different hardware configuration inside”.
...
[Error] reference to 'distanc
#include <iostream>
#include <conio.h>
using namespace std;
#include<iostream>
#include<conio.h>
using namespace std;
struct distance //structure
{
int foot;
float inches;
};
int main()
{
distance a,b;
distance c={3,6.34};
cout<<"Enter feet and inches of distance a"<<endl;
cin>>a.foot<<a.inches<<endl;
b.inches=c.inches+a.inches;
b.foot=c.foot+a.foott;
cout<<"distance a: "<<a.foott<<a.inches<<endl;
cout<<"distance b: "<<b.foott<<b.inches<<endl;
cout<<"distance c: "<<c.foott<<c.inches<<endl;
getche();
return 0;
}
washing machine c++
celcius for cotten clothes 40degree celcius per quick wash and 1000 revolution for rinse and
dry only using Microsoft visual STUDIO 2010 c++ programming
//please this is all i could do, help improve in respect to the question
using namespace std;`
using namespace std;
int main()
{
int tempsensor; //from the temperature sensor console
int revolcycle=1000; //gotten from the motor console
int timer =1 ;
char washtype;
int revolution = revolcycle/timer;
char cotton;
char quickwash;
if (washtype = cotton) //link to a button in the machine through console
{
tempsensor = 80;
cout <<"ready for cotton";
return (0);
}
if (washtype = quickwash)
{
tempsensor = 40;
cout<<"ready for quick wash\n";
}
if (revolution = 1000)
{
char rinse;
char dry;
}
{
system ("pause");
}
}
`
translate this into cmake.
I write a parallel program with the PETSc, it can compiled sucessfully with the following command. could you please help me to translate it into a cmake file. so i can further develop the code in kdevelop4.4.
mpic++ main.cpp -o main -I/home/ztdep/Downloads/petsc-3.3-p6/include -I/home/ztdep/Downloads/petsc-3.3-p6/arch-linux2-cxx-opt/include -Wl,-rpath,/home/ztdep/Downloads/petsc-3.3-p6/arch-linux2-cxx-opt/lib -L/home/ztdep/Downloads/petsc-3.3-p6/arch-linux2-cxx-opt/lib -lpetsc -lX11 -Wl,-rpath,/home/ztdep/Downloads/petsc-3.3-p6/arch-linux2-cxx-opt/lib -lHYPRE -lcmumps -ldmumps -lsmumps -lzmumps -lmumps_common -lpord -lsuperlu_dist_3.1 -lparmetis -lmetis -lscalapack -lblacs -lpthread -llcg -lflapack -lfblas -lm -L/usr/lib64/gcc/x86_64-suse-linux/4.7 -L/usr/x86_64-suse-linux/lib -lmpichf90 -lgfortran -lm -lgfortran -lm -lquadmath -lm -lmpichcxx -lstdc++ -ldl -lmpich -lopa -lmpl -lrt -lpthread -lgcc_s -ldl
guys pls help. can you make this program by using c++ programming language.
Introduction
ARP ARP Talk is a fun variation of the English language. The conversion to ARP ARP is carried out as follows:
1. When a vowel or vowel sound (a, e, i, o, u, or y as in why) is found, arp is placed in front of it.
2. Two or more vowels together are treated as one.
3. If a vowel or vowel sound occurs as the final letter of a word, it is only given an arp if it is the only vowel or vowel sound in the word.
Examples
fish becomes farpish
Harry becomes Harparry
Condition becomes carpondarpitarpion
Problem
Write a program which will convert an English sentence into Arp Arp language.
Input
A string or sentence terminated by the end-of-line character.
Output
The string or sentence converted to arp arp talk.
Input Validation
None. The input will always be a valid English sentence/phrase.
Sample Run
Why was I really unconscious while the avalanche roared all about me?
Wharpy warpas arpI rarpeally arpuncarponscarpious wharpilarpe tharpe arpavarpalarpancharpe rarpoararped arpall arpabarpout marpe?
Read data from a .txt file into to the program to prefrom calculations
Be able to calculate mean, standard deviation, and median. Data should be sorted using insert sort first though.
The program must be able to accept input from an input file and print a report to an output file. These files are to be named by the user at runtime.
I first wrote this program so that it would ask for user to enter the numbers, instead of reading from a file. And output to the screen of course. It worked just as it is supposed to, so I know that the algorithm for the calculations is not wrong. The problem started when I modified the program to read from a file, and print to a file. I am almost sure that the problem is that the program cannot read or store in the arrays, properly. It throws(print) out bunch of nonsense. You can try it out using the attached txt file to see what I mean. Here is my source code:
include <cmath>
include <iostream>
include <fstream>
include <iomanip>
using namespace std;
const int Max_Size = 200;
void print (ofstream& outdata, double list[], int lenth);
void insertionSort (ofstream& outdata, double list[], int lenth);
void median (ofstream& outdata, double list[], int lenth);
void mean (ofstream& outdata, double list[], int lenth);
double standard_deviation(ofstream& outdata, double list[], int lenth);
void readdata(ifstream& indata, double list[], int& lenth, bool& lenthok);
int main()
{
double dataarray[Max_Size];
int datalenth;
bool lenthisok;
ifstream indata;
ofstream outdata;
char inputfile[20];
char outputfile[20];
cout<<"Please enter the input file name:"<<endl;
cin>>inputfile;
indata.open(inputfile);
if(!indata)
{
cout<<"Cannot open the input file."<<endl;
return 1;
}
cout<<"Please enter the output file name: "<<endl;
cin>>outputfile;
outdata.open(outputfile);
{
readdata(indata, dataarray, datalenth, lenthisok);
if (lenthisok)
insertionSort(outdata, dataarray, datalenth);
else
cout<<"Lenth of the secret code must be <="<<Max_Size<<endl;
print (outdata, dataarray, datalenth);
median(outdata, dataarray, datalenth);
mean(outdata, dataarray, datalenth);
standard_deviation(outdata, dataarray, datalenth);
}
indata.close();
outdata.close();
return 0;
}
void readdata(ifstream& indata, double list[], int& lenth, bool& lenthok)
{
int i;
lenthok = true;
indata>>lenth;
if (lenth>Max_Size)
{
lenthok = false;
return;
}
for (i=0; i<lenth; i++)
indata>>list[i];
}
void insertionSort(ofstream& outdata, double list[], int lenth)
{
int firstoutoforder;
int location;
double temp;
for (firstoutoforder=1; firstoutoforder < lenth; firstoutoforder++)
if (list[firstoutoforder] < list[firstoutoforder-1])
{
temp = list[firstoutoforder];
location = firstoutoforder;
do
{
list[location] = list[location-1];
location--;
}
while (location > 0 && list[location-1] > temp);
list[location] = temp;
}
}
void print (ofstream& outdata, double list[], int lenth)
{
int i;
outdata<<"Using insertion sort algorithm, the elements are:"<<endl;
for (i=0; i<lenth; i++)
outdata<<list[i]<<" ";
}
void median (ofstream& outdata, double list[], int lenth)
{
int middle;
double median;
middle = lenth / 2;
if (lenth % 2==0)
{
median = (list[middle-1] + list[middle]) / 2;
}
else
median = (list[middle]);
outdata<<"\nThe median for the elements entered is:"<<median<<endl;
}
void mean (ofstream& outdata, double list[], int lenth)
{
double sum = 0;
double average = 0;
int i;
for (i=0; i<lenth; i++)
sum = sum+list[i];
average = sum/lenth;
outdata<<"\nThe Mean is:"<<average<<endl;
}
double standard_deviation(ofstream& outdata, double list[], int lenth)
{
double sum = 0;
double average = 0;
double sq_diff_sum = 0;
double variance = 0;
double diff = 0;
int i;
double deviation = 0;
for (i=0; i<lenth; i++)
sum = sum+list[i];
average = sum/lenth;
for (i=0; i<lenth; i++)
{
diff = list[i] - average;
sq_diff_sum += diff * diff;
}
variance = sq_diff_sum/lenth;
deviation = sqrt(variance);
outdata<<"\nThe Standard Deviation is:"<<deviation<<endl;
return (deviation);
}
// end of code
How do I display all the files and sub folders, and their subfolders?
I have this code but it isn't working the way I would like it to:
#include <Windows.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
WIN32_FIND_DATA wfd;
HANDLE hf;
string findwhat, findwhat2;
string path = "C:";
findwhat = path + "\\*";
hf = FindFirstFile(findwhat.c_str(), &wfd);
while(hf != INVALID_HANDLE_VALUE)
{
if(wfd.cFileName[0] != '.' && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
string found;
found = path + "\\" + wfd.cFileName;
cout<<found<<endl;
HANDLE hf2;
WIN32_FIND_DATA wfd2;
findwhat2 = path + findwhat + found + "\\";
hf2 = FindFirstFile(findwhat2.c_str(), &wfd2);
if(wfd2.cFileName[0] != '.' && (wfd2.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
cout<<"---->"<<wfd2.cFileName<<endl;
}
}
if(!FindNextFile(hf, &wfd))
{
FindClose(hf);
hf = INVALID_HANDLE_VALUE;
}
}
cin.get();
}
How do I fix it?
decimalNumberToConvert[1] not declared
#include <iostream>
#include <conio.h>
using namespace std;
void toBinary(long long decimal, int binary_number_array[], int & NumBinaryBits);
int main()
{
long long decimalNumberToConvert[1] ;
cout<<"Enter a decimal number"<<endl;
cin>>decimalNumberToCovert[1];
int sizeBinaryNumber, binaryNumberArray[100];
toBinary(decimalNumberToConvert, binaryNumberArray, sizeBinaryNumber);
//Printing out the binary number
cout << " The binary equivalent of " << decimalNumberToConvert << " : ";
for (int i = 0; i < sizeBinaryNumber; ++i)
cout << binaryNumberArray[i];
cout <<endl;
getch();
return 0;
}
void toBinary(long long decimal, int binary_number_array[], int & NumBinaryBits)
{
long long decimalNumberToConvert[1] = decimal;
NumBinaryBits = 0;
do
{
binary_number_array[NumBinaryBits++] = decimalToConvert % 2;
decimalNumberToConvert[1] /= 2;
}
while (decimalToConvert);
for (int i = 0; i <= NumBinaryBits / 2; ++i) std::swap(binary_number_array[i], binary_number_array[NumBinaryBits - i - 1]);}
std::map help!!
compiler error
a.cpp:20:55: error: conversion from ‘std::map<std::basic_string<char>, Object*>::iterator {aka std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, Object*> >}’ to non-scalar type ‘std::map<std::basic_string<char>, Object>::iterator {aka std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, Object> >}’ requested
a.cpp:20:71: error: no match for ‘operator<’ in ‘itr < _c.std::map<_Key, _Tp, _Compare, _Alloc>::end<std::basic_string<char>, Object*, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, Object*> > >()’
my code
#include "object.hpp"
#include <map>
int main()
{
std::map<string, Object*> _c;
Object *a = new Object();
Object *b = new Object();
Object *c = new Object();
Object *d = new Object();
_c["dbdb"] = a;
_c["dbh"] = b;
_c["dbdfgdb"] = c;
_c["dbdbgdsfg"] = d;
for( std::map<string, Object>::iterator itr=_c.begin(); itr < _c.end(); itr++)
{
}
}