Thanks! The problem is that the size will change with every different array that I'm sending to the function so I have to find another way to initialise it...
Thanks! The problem is that the size will change with every different array that I'm sending to the function so I have to find another way to initialise it...
I don't tend to use Arrays when programming in C++ because I think that vectors are a lot easier to use.
The problem is that now I have to use arrays. I'm creating a game using SDL. I'm trying to create the artwork in code using pixels on the screen. So all the artwork information is stored in Multidimensional Arrays. I'm trying to create a function that will draw the bitmap on the screen but the problem is that I dont know how to pass a multidimensional array as a parameter to the function. I know the size of the bitmap that I'm passing to the function but I'm not sure how to initialise the parameters.
This is an example of the code - fail to compile
#include <iostream>
int bitmap[5][5] = {
{0,0,1,0,0},
{1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1},
{0,0,1,0,0}
};
void DrawBitmap(int arr[0][0], int w, int h)
{
for(int i=0;i<w;i++)
{
for(int j=0;j<h;j++)
{
if(arr[w][h] == 1)
{
// draw pixel on the screen
}
}
}
}
int main (int argc, char * const argv[])
{
DrawBitmap(bitmap, 5, 5);
return 0;
}
Hi Guys,
I have a question about PHP and Ajax/Javascript SetInterval.
Im working on an application that users will be able to subscribe to and I want
an email sent to them after !exactly 24 hrs. The only way that I could think of doing
something like this is by creating an interval that will execute an Ajax function that will call a php function that compares the user subscription timestamp to the current timestamp and if it's greater than 24 hrs it will send the email.
The application is working fine, but I just realized that when the browser is closed,
the SetInterval functions stop working?! I thought that after executing it once it will keep working on the server but I was wrong... I tried to create a simple application that uses php/ajax and logs the current timestamp every 3 seconds into a txt file, again it's working fine but only when the browser page that have the script on is open!
Is there a way to create an interval that keeps working on the server without anyone viewing the page that calls the function ?
Thanks
Sessions wont work if cookies are disabled in the browser..
You'd be surprised, some mobile phone browsers has cookies disabled by default!
How about storing the information in a session variable
As far as i know, the only two possible ways to send data between two pages is using GET and POST super global arrays. You can use ajax to send information via post but that will only work if you're staying on the same page. The most common way to solve this problem is to hash the id string using something like md5 encryption and then decrypt the md5 string in the next page to get the value back, its easy to do, and secured enough for most common tasks...
Hi.
Im working on a tumblr like website application.
The users will be able to comment on a posted article etc.
At the moment, the site uses gravater to retrieve users gravater photos.
However, the requirements has changed, and now i need, if possible, to get the users facebook profile photo instead. all the details that the user supply when entering a comment is name, email and the actual comment. is there a way to retrieve the users fb profile photo using his email address ?
Thanks
Hi,
Im working on an application that works on a timer.
There is a timer on a product, and when the timer expires, the application dispatch
the NextProduct method that set the next product in queue to be the active one and resets the timer. The timer is basiclly an Ajax function that's being called every minute and updates the timer on screen. everything seem to work fine, but what happens if no one is viewing the website ?
Does the timer works on the server all the time, or in order for the ajax function to work, some one needs to be on view the website ?
Thanks
Hey,
Im working on an application that will let me send group emails using PHP.
All the emails are going to be stored in a database.. I expect to have a lot of
email addresses, maybe thousands. Ive used the MAIL function before to send individual emails but i never tried to send a group email...
I just wanted to know if the way to do it is: looping through all the emails in the database and use the mail function on each one of them ? wouldn't they all go to the junk mail because it's an auto generated email ? and if so, how does all the other mailing group application works ?
also, i want the email to be an HTML/CSS email. I did it before, but this time, it suppose to look like a newsletter, and some of the template information that's going to be in the newsletter will have to come from a db. the tricky part is, i assume that the template will change from time to time, i was thinking about creating html templates and open them using php fopen, copy all the information to a variable and use the variable as the message body, the only problem is, that i want the html template to include some PHP in order to retrieve some information from the database, is there a way to do that ? or the only way is to echo the html directly into a …
Hey
I have a problem with background repeating and positioning in IE.
For some reason the background of the header and the shadow underneath it is not repeating but there is another div tag inside of the header div tag and the background is repeating just fine! Help will be much appreciated.
Thanks
link:
http://www.meowgirl.com.au/testing-server/home.php
HTML
<div id="header">
<div id="grass">
<img src="images/header_banner.png" alt="Meow Girl - Online Shop Banner" />
</div>
</div>
<div id="shadow"></div>
CSS
#header
{
height: 231px;
width: 100%;
background-image: url('../images/header_background.png');
background-repeat: repeat-x;
text-align: center;
}
#grass
{
height: 231px;
width: 100%;
background-image: url('../images/header_grass.png');
background-repeat: inherit;
}
#shadow
{
height: 13px;
width: 100%;
background-image: url('../images/shadow.png');
background-repeat: inherit;
}
Following these steps will help you avoid php-mysql errors and will clean
up your code a little....
1.create a $query variable (echo, copy and past it in mysql command line)
[If it's not working you have a problem with your query)
2.create a $result variable and store mysql_query($query, $connection); in it.
Create a simple test
if (!$result)
{
die ("Database query failed" . mysql_error());
}
[if you get this error on the screen you have a problem with your connection settings (sql query should be tested in step1)].
3. Use $row = mysql_fetch_row($result);
also, thats not the proper way to check if the
array is empty "if($userQuery[0] > 0)"
try this - " if (isset($userQuery[0])) "
isset will return a bool of true or false
$_POST is an associative array.
print_r() Prints human-readable information about a variable and it is the best
function to use when you want to print arrays...
since $_POST is an array, the best way to echo it is using print_r()...
I tried echo before printing the whole array and it's not working!
It doesn't really matter since it's case-insensitive....
It's really frustrating
I just don't see the problem! im starting to think that there is a problem on my local server settings....
Simple HTML form is not working properly...
attached is a simple HTML form.
When i print the super global $_POST[] i don't get any information from the text fields.
Im really frustrated... I can't find any problem with the code...
HTML
<form method="POST" action="functions/process_payment.php" >
<table id="creditCards">
<tr>
<td><input type="radio" name="creditCard" class="CreditCard" checked value="Visa"/><img src="images/checkout/visa.png" /> Visa</td>
<td><input type="radio" name="creditCard" class="CreditCard" value="Mastercard"/><img src="images/checkout/master.png" /> Master Card</td>
<td><input type="radio" name="creditCard" class="CreditCard" value="Amex"/><img src="images/checkout/amex.png" /> Amex</td>
</tr>
</table>
<table id="paymentInfo">
<tr>
<th>Card Holder Name:</th>
<td><input type="text" name"cardHolderName" id="CardHolderName" /></td>
</tr>
<tr>
<th>Card Number:</th>
<td><input type="text" name"cardNumber" id="CardNumber" /></td>
</tr>
<tr>
<th>Card Expiry:</th>
<td>
<select name="ddlExpiryMonth" id="ddlExpiryMonth">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="ddlExpiryYear" id="ddlExpiryYear">
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
</select>
</td>
</tr>
</table>
<table id="buttonsTable">
<tr>
<td> <input type="image" name="processPayment" src="images/checkout/processPayment.png" width="119" height="39"></td>
<td><a href="functions/cancel_order.php"><img src="images/checkout/cancelOrder.png" /></a></td>
</tr>
</table>
</form>
PHP File
<?php
print_r($_POST);
?>
Output
Array ( [creditCard] => Visa [ddlExpiryMonth] => 01 [ddlExpiryYear] => 10 [processPayment_x] => 72 [processPayment_y] => 30 )
Hi Guys,
I just installed PDFLib,
Im trying to create automatic invoice system for one of my clients.
Im testing using MAMP on mac OSX10.5.
I used the PDFLib manual and installed the extension.
Im pretty sure that everything is working because i can see the
extension information in my phpinfo().
I created a php file that creates a dynamic pdf file but for some reason i can't
open it. The pdf file size is 0kb and when im trying to open it, it says that the file is damaged... but php doesnt throw any errors back...
I was wondering if some1 in the community have had any experience with PDFLib and can help me. Thanks
<?php
$pdf = PDF_new();
pdf_open_file($pdf, "heloworld.pdf");
pdf_begin_page($pdf, 595, 842);
$arial = PDF_findfont($pdf,"Arial","host",0 );
pdf_setfont($pdf, $arial, 10);
pdf_show_xy($pdf, "Hellow World? ",50, 750);
pdf_show_xy($pdf, "Test 1, 2, 3, 4 working. ", 50,730);
pdf_end_page($pdf);
pdf_close($pdf);
?>
So if someone types a message in an HTML text box and hit
return, the computer generates a \n automatically ?
thanks for all your help...
Yeah,, but my client is going to do the typing and he just want
to hit return and go to the next line without having to add extra characters
Hi,
I created a couple of web applications with php and mysql and i have
a problem that keeps coming up.
I want to use html text boxes that will send information to the
database but i want it to include line breaks....
until now i just typed in <br/> at the end of the line but this time
it's for a client and i have to implement line breaks to the database.
is there a php function that can handle that ?
Thanks!
Ok, so i figured the problem but im not sure about the solution...
The reason i get null is because the onload function is triggered before the DOM has been fully loaded and that's way it can't pick up errorBox.
I tried to put the script tags at the end of the HTML document and it's working fine, but im not sure if it's good practice or even valid to do it.
Is there a better way to make sure that the DOM is fully loaded before triggering a function ?
Hi Guys, im pretty sure that all of the spelling is correct.
Attached is a piece of code that should give you an idea
of what im trying to do.
javascript is embedded to html and still not working...
<?php
session_start();
$page = "";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="styles/style.css" />
<link rel="stylesheet" type="text/css" href="styles/registrationstyles.css" />
<title>Ivory Computers - Computer Seller Sydney Bondi | Computer Repairs Sydney Bondi</title>
<script type="text/javascript">
document.getElementById("errorBox").style.visibility="hidden";
</script>
</head>
<body>
<div id="siteContent">
<?php include("header.php"); ?>
<div id="pageTitle">
<img src="images/misc/registration.png" alt="Ivory Computers - Sales and Repairs" />
<h2>Hi! Ready to register with Ivory Computers?<br/></h2>
</div>
<div id="registrationForm">
<div id="errorBox">
Please type in your first name<br />
Please type in your last name<br />
Please type in your address<br />
Please type in your city<br />
Please enter your postcode <br />
Please enter a valid email address<br />
Please enter a valid phone number<br />
Please enter a valid mobile number<br />
Please enter a valid username<br />
Please enter a valid password: 6-8 characters<br />
</div>
Hi everyone,
Im having some issues with a website that im working on.
The website have mysql database and all of the server side code is done in php, therefor all of the files are named with a .php extension,
I know it shouldn't make any different but for some reason i can't access the document elements using javascript... im not a js expert but i know the basics and i use it mostly for forms validation, but every time i try to use getElementById, i get nothing back, when i try to use alert and reference it i get null....
That's my js file
// Registration From Validation
window.onload = initForm();
function initForm(){
document.getElementById("errorBox").style.visible = "hidden";
}
It's an external file but it's embedded properly, and im sure of that
because the alert function is working....
Please note that getElementById doesn't work on anything....
I tried all of my document id's and i can't change any property
or create new information in any of those id's.
I'm pretty frustrated by now and help will be appreciated...
Thanks
Hi , im trying to create a simple code that generate random numbers
Im having two problem ,
1. For some reason randomize() function does not work on VisualC++6
2. I didnt really got the idea on how to set the range of the numbers that will be generated using the rand() function ,. i just saw it in some example .
Here is the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
randomize();
for (i=0;i<10;i++)
printf ("Number %d: %d\n",i+1,rand()%10+1);
return 0;
}
Thanks for the help guys !
can you please post a code example ?
Well im trying to find a string in a textfile but i have some problems :
When im trying to create a string called temp in the Compare function using the length of the string that was typed in to main to compiler gives me an error , and even if ill type in the code the size of temp the program will still not work . any1 have any ideas ?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void Compare(FILE *filein,char *str,int length,char *source)
{
char temp[length];
fgets (temp,length,filein);
if (strcmp (temp,str) == 0)
{
printf ("The string : %s was found in the source file %s.\n",str,source);
printf ("Press any key to terminate the program...\n");
getch();
fclose(filein);
exit(0);
}
}
int main()
{
FILE *fin;
char str[40];
char source[40];
char ch;
int length;
printf ("Enter the string the you are looking for: ");
gets(str);
printf ("Enter the source file that will be searched: ");
gets(source);
fin = fopen(source,"rt");
length = strlen(str);
if (fin == NULL)
{
printf ("Failed to open source file..\n");
exit(1);
}
while (ch!=EOF)
{
ch = fgetc(fin);
if (ch == str[0])
Compare(fin,str,length,source);
}
printf ("The string %s was not found under the file %s\n",str,source);
printf ("Press any key to terminate the program...\n");
getch();
fclose(fin);
return 0;
}
Im trying to read some integers values from a text file.
The problem is that first lines of the text files contains some text and only then theres the values that i want to read into variables , and i dont know how to get down three lines and then read using fscanf .
TEXT FILE(storeinfo.txt):
Stores Information:
Store Code Store Size Store Workers Store Income
951 1200 7 67000
952 1452 12 92833
953 800 5 41000
954 1000 6 61000
955 1500 12 100321
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int code;
int size;
int workers;
int total;
}store;
int main()
{
int i;
FILE *filein;
char source[40];
store storearr[5]={0};
printf ("Enter a source filename: ");
gets(source);
filein = fopen (source,"rt");
if (filein == NULL)
{
printf ("Unable to open sourcefile...\n");
exit(1);
}
for (i=0;i<5;i++)
fscanf(filein,"%d %d %d %d\n",&storearr[i].code,&storearr[i].size,&storearr[i].workers,&storearr[i].total);
for (i=0;i<5;i++)
printf ("%-15d %-15d %-15d %-15d\n",storearr[i].code,storearr[i].size,storearr[i].workers,storearr[i].total);
fclose (filein);
return 0;
}
Thank it works , but way i cant use the other conio.h commands like clrscr() ?
Hi guys,
when ive used Turbo c compiler and i wanted to put the program
ona "wait key" status until the user hit sum key , ive used getch(); .
when i try to use this command in Visual C++ 6.0 im getting an error..
Is there a diffrent command to do it that works in vc6 ??
Hi , is there a way to download filess from the internet using c ?
ive just saw your post Ancient Dragon , but i already did it . so thanks anyway ...
Big thanks for all of you guys !!
Finally ive solved it , thanks for the realloc . its just that if i resize the array to array[n-1] the last number is beeing deleted , so what i did is pushing the number that the user wishes to erase to the end of the array and resize if to array [n-1]. ive also used realloc for the add function , it makes the function really smaller and understandable , . so thanks !!!.
anyway here is the code and its FINALLY working.
#include <stdio.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
void memoryTest(int *array)
{
if (array == NULL)
{
printf ("Error: Failed to allocate memory!\n");
printf ("Press any key to terminate the program...\n");
getch();
exit(1);
}
}
int* AddNumber (int *array,int size,int var)
{
array = (int *) realloc (array,sizeof(int) * size);
memoryTest(array);
array[size-1] = var;
return array;
}
int* EraseNumber (int *array,int size,int var)
{
int i,tmp=0;
for (i=0;i<size+1;i++)
{
if (array[i] == var)
tmp = 1;
}
if (tmp == 0 || array == NULL)
{
printf ("Error: No such number in array!\n");
printf ("Press any key to return into the main menu...\n");
getch();
return array;
}
tmp = 0;
for (i=0;i<size;i++)
{
if (array[i] == var)
{
tmp = array[i+1];
array[i+1] = array[i];
array[i] = tmp;
}
}
array = (int *) realloc (array,sizeof(int) * size);
memoryTest(array);
return array;
}
void PrintArray(int *array,int size)
{
int i;
putchar ('\n');
printf ("***** PRINTING ARRAY *****\n");
putchar ('\n');
for (i=0;i<size;i++)
printf ("%d,",array[i]);
putchar('\n');
getch();
} …
well i thought i should create a new array cause i have no idea how i can remove a number from the array using realloc ...
I dont get it , what do you mean by "diffrent variables to keep track of the indexes" ?
can you give me an example ?
thanks.
Hi , im trying to create a program that could delete number from an array and resize the array to the correct size .
Array[0] = 32
Array[1] = 30
Array[2] = 40
Array[3] = 31
Array[4] = 61
Deleting the number 40
New array
Array[0] = 32
Array[1] = 30
Array[2] = 31
Array[3] = 61
This is the code that i came up with but i have no idea why it wont work ...
#include <stdio.h>
#include <alloc.h>
#include <stdlib.h>
int main()
{
int *array,i,size = 5,var,temp=0,*array2;
array = (int *) malloc (size * sizeof(int));
for (i=0;i<5;i++)
{
printf ("Enter number: ");
scanf ("%d",&array[i]);
}
printf ("Enter a number to delete: ");
scanf ("%d",&var);
for (i=0;i<size;i++)
{
if (array[i] == var)
{
array[i] = 0;
temp = 1;
}
}
if ( temp == 0)
{
printf ("No such number in array!\n");
printf ("Press any key to terminate the program...\n");
getch();
free (array);
exit (1);
}
array2 = array;
free (array);
size--;
array = (int *) malloc (size * sizeof(int));
for (i=0;i<size;i++)
{
if (array2[i] != 0)
array[i] = array2[i];
}
putchar ('\n');
printf ("PRINTING ARRAY: ");
for (i=0;i<size;i++)
printf ("%d,",array[i]);
putchar('\n');
getch();
free (array);
free (array2);
return 0;
}
Hi, im trying to create a program that will control a dynamic array .
The program have few functions to handle dynamic array.
* Add number to array
* Erase number from array
* Print the array
I have two problems with my code .
The first one is with the EraseNumber function .
I just cant understand why it doesnt work like it should ,
The second is that every time that the menu pops up , that text
Of the menu start to be really messy for some reason .
Maybe one of you would take a look at the code and tell me what he
Thinks that the problem is .
Btw. im using Turbo C , and im runing it on a win2k OS.
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <conio.h>
// Functions proto-type
void mainMenu();
void memoryTester(int *array);
int* addNumber(int *array,int arraysize,int var);
int* eraseNumber(int *array,int arraysize,int var);
void printfArray(int *array,int arraysize);
// Main function
int main()
{
int *array = NULL;
int arraysize = 0;
int var = 0;
int choice;
// Main loop
while (choice != 4)
{
mainMenu();
printf ("Enter your choice: ");
scanf ("%d",&choice);
switch (choice)
{
case 1: printf ("Add number: ");
scanf ("%d",&var);
arraysize++;
array = addNumber(array,arraysize,var);
break;
case 2: printf ("Erase number: ");
scanf ("%d",&var);
arraysize--;
array = eraseNumber(array,arraysize,var);
break;
case 3: putchar('\n');
printf ("**** PRINTING ARRAY ****\n\n");
printfArray (array,arraysize);
getch();
break;
case 4: …
Finally i got it.
btw; the characters should be in a random order and i only need the use of one counter;
#include <stdio.h>
void Compact(char *source,char *dest);
int main(void)
{
char str1[40],str2[40];
printf ("String << ");
gets (str1);
Compact(str1,str2);
printf ("String >> ");
puts (str2);
return 0;
}
void Compact (char *source,char *dest)
{
char var = *source;
int counter = 0;
while (*source)
{
if (var == *source)
{
counter++;
source++;
}
if (var != *source || !*source)
{
*dest = counter + '0';
dest++;
*dest = var;
dest++;
var = *source;
counter = 0;
}
}
*dest = '\0';
}
the thing is that i got to use pointers , does any1 know why my code is not working ?
well ive done some edites to the code but still nothing.
#include <stdio.h>
void compact(char *source, char *dest)
{
char var = *source;
int counter=0;
while (*source)
{
if (var == *source)
{
counter++;
source++;
}
else
{
*dest = counter + '0';
*(dest+1) = var;
dest++;
}
var = *source;
counter=0;
}
*dest = '\0';
}
int main(void)
{
char strsource[40],strdest[20];
printf ("String: ");
gets (strsource);
compact(strsource,strdest);
puts (strdest);
return 0;
}
I need to create a function the gets a source string pointer and a destination string pointer , so if the source string will contain -
"aaaabbbbbbcccdd"
the function will return a destination string that contains
"4a6b3c2d"
This is my code , but its not working and for some reason i can tell why
#include <stdio.h>
void compact(char *source, char *dest)
{
char var = *source;
int counter=0;
while (*source)
{
if (*source == var)
{
counter++;
source++;
}
else
{
*dest = counter + '0';
*(dest+1) = var;
dest++;
}
var = *source;
}
*dest = '\0';
}
int main(void)
{
char strsource[40],strdest[20];
printf ("String: ");
gets (strsource);
compact(strsource,strdest);
puts (strdest);
return 0;
}
got it , and ive fixed the problem , thanks Narue , and thanks to every1 who tried to help ..
Thanks but i think i got it with out the example ,
This is what ive tried to create ...
ive tried it a couple of times and its seems to work , what do you think
guys ?
#include <stdio.h>
int underStringPos(char *source,char *under)
{
char *sourceptr = source;
int counter=0;
while (*sourceptr){
if (*sourceptr == *under){
char *s = sourceptr, *u = under;
while (*u){
s++,u++;
if (*s != *u)
break;
return counter;}}
sourceptr++;
counter++;}
}
void main()
{
char str1[40],str2[40];
int num;
printf ("Enter main string: ");
gets(str1);
printf ("Enter under string: ");
gets(str2);
num = underStringPos(str1,str2);
printf ("UnderStringPos = %d\n",num);}
Im using Turbo C / Visual C++ 6.0 and my OS is windows 2000
yeah i know , how can i draw a box using graphics library , and what library should i use
im looking for a way to create a box with pixels .
Im trying to write my own function that does this with array pointers so there is no point to use an existing function .
Hi, im trying to create a function that gets two strings , the first string its the source , and the seconed is an understring .
the function should return an int with the value of the position that the understring starts in the source string . so that if ill have thie string as source : "abcdefg" and understring :"efg", than the function should return 5 because "efg" starts at the fifth character of the source string.
i need to do this with array pointers , so any1 has any idea ?
Is there a function that draw 2d objects like boxes and circles .
I remember that in qbasic there was a few 2dobjects functions so i thought that there is a chance c will have some too.
Thanks .
Thanks guys , you were totally helpful .