I run [url]http://freshborngold.com/[/url] and is there any possible way i can optimise it so that it runs quicker, it takes too long. I'm using GoDaddy for webhosting, and it's a Wordpress site.
Yep, you can go the the Web Development section.
And unless you have a really shitty code, you can't make it run quicker, send a mail to GoDaddy.
[QUOTE=Wyzard;24929631]Have you checked whether the filename is actually in the args array as you expect? If it's there, is it different from what you get when you type it on a command line?[/QUOTE]
I can't since the program crashes. Doesn't even start or anything. I just get the send error report after a few seconds.
Would DirectDraw be the fastest option for manually plotting each pixel on the screen?
I need to achieve game worthy framerates.
And I don't care for primitives or fancy functionality, I just want to plot pixels.
Using Shaders will be the fastest way I believe, since they are executed right on the graphics hardware.
[editline]11:10PM[/editline]
Depends on the kind of plotting you will do though.
If it is completely dynamic and you cannot easily use a pre-compiled shader, it might be faster to calculate the pixels on the CPU and upload the data to the graphics hardware than having to re-compile a shader and upload it. Which API you are using for this will probably not matter.
You can also take a look at stuff like CUDA and OpenCL.
[QUOTE=ZeekyHBomb;24944847]Using Shaders will be the fastest way I believe, since they are executed right on the graphics hardware.
[editline]11:10PM[/editline]
Depends on the kind of plotting you will do though.
If it is completely dynamic and you cannot easily use a pre-compiled shader, it might be faster to calculate the pixels on the CPU and upload the data to the graphics hardware than having to re-compile a shader and upload it. Which API you are using for this will probably not matter.
You can also take a look at stuff like CUDA and OpenCL.[/QUOTE]
Aye, it's 100% dynamic. I'll take a look at OpenCL. Thanks :)
[QUOTE=Darwin226;24940331]I can't since the program crashes.[/QUOTE]
It doesn't [i]finish[/i] running successfully because it crashes, but it at least [i]starts[/i] running. You should be able to put some print statements at the beginning of Main().
What happens if you comment out all the code in Main(), leaving it an empty method? If it doesn't crash then, you can add code back, a little at a time, to figure out what's making it crash.
[QUOTE=Darwin226;24940331]I can't since the program crashes. Doesn't even start or anything. I just get the send error report after a few seconds.[/QUOTE]
Add a try catch block round your startup code, and when it catches make it messagebox the error.
C#
[code]
try
{
// code here
}
catch(Exception ex)
{
Messagebox.Show(ex.ToString());
}[/code]
What I would do is set a breakpoint on the first line.
Need some C help here. I'm relatively new so please keep it simple.
I'm making a simple calculator program. I have an function (int if I didn't use the correct terminology) called add() that I want to activate if the program is ran with the command line argument "-add" - I've tried to adapt some code samples but never got it working. I know how to activate the functions (use add(); by itself) but I'm not sure how to activate it when using an argument.
[QUOTE=Sonicfan574;24951933]Need some C help here. I'm relatively new so please keep it simple.
I'm making a simple calculator program. I have an function (int if I didn't use the correct terminology) called add() that I want to activate if the program is ran with the command line argument "-add" - I've tried to adapt some code samples but never got it working. I know how to activate the functions (use add(); by itself) but I'm not sure how to activate it when using an argument.[/QUOTE]
Read this: [url]http://www.cprogramming.com/tutorial/c/lesson14.html[/url]
argc provides the number of arguments and argv[] is a list of them. You need to check if argv[1] is "-add".(note: argv[0] is always your program's name)
[cpp]
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
int addflag = 0;
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-add") == 0) {
addflag = 1;
break;
}
}
if (addflag) {
/* add values and print here */
}
}
[/cpp]
:ninja:
[QUOTE=IpHa;24952074]Read this: [url]http://www.cprogramming.com/tutorial/c/lesson14.html[/url][/quote]
Seen this already.
[QUOTE=IpHa;24952074]argc provides the number of arguments and argv[] is a list of them. You need to check if argv[1] is "-add".(note: argv[0] is always your program's name)[/QUOTE]
That was pretty confusing, thanks for clearing that up. But how do I check if argv[1] is -add? I tried using
[code]if ( argv[1] = "-add" )[/code]
and the compile failed.
[editline]07:44PM[/editline]
[QUOTE=ROBO_DONUT;24952090][cpp]
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
int addflag = 0;
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-add") == 0) {
addflag = 1;
break;
}
}
if (addflag) {
/* add values and print here */
}
}
[/cpp]
:ninja:[/QUOTE]
Oh lol, thanks.
[QUOTE=Sonicfan574;24952134]Seen this already.
That was pretty confusing, thanks for clearing that up. But how do I check if argv[1] is -add? I tried using
[code]if ( argv[1] = "-add" )[/code]
and the compile failed.[/QUOTE]
A C string is an array of chars. A C array is a pointer to a some memory. Thus, a C string is a pointer to a bunch of chars.
You're comparing pointers.
You need to use the string.h function strcmp().
[QUOTE=ROBO_DONUT;24952165]You're comparing pointers..[/QUOTE]
No, he's assigning a char array to a pointer. Which results in a compiler error.
[QUOTE=Agent766;24952190]No, he's assigning a char array to a pointer. Which results in a compiler error.[/QUOTE]
I saw that and assumed he meant "==".
[QUOTE=ROBO_DONUT;24952208]I saw that and assumed he meant "==".[/QUOTE]
Probably, but that wouldn't cause a compiler error.
[editline]09:49PM[/editline]
Would it? I use C++, not C.
[QUOTE=Agent766;24952221]Probably, but that wouldn't cause a compiler error.
[editline]09:49PM[/editline]
Would it? I use C++, not C.[/QUOTE]
Lets see.
[code]int main(int argc, char **argv) {
argv[0] = "A HOLLOW VOICE SAYS PLUGH";
return 0;
}[/code]
[code]
╭─┄┈
│completed at 22:56:29, status: :3
│mike at mike-laptop in /tmp
╰─┄┈
% gcc -o test test.c
╭─┄┈
│completed at 22:56:36, status: :3
│mike at mike-laptop in /tmp
╰─┄┈
% ./test
╭─┄┈
│completed at 22:56:40, status: :3
│mike at mike-laptop in /tmp
╰─┄┈
%[/code]
Nope.
C lets you shoot yourself in the foot. The most it would ever do is give you a warning, not an error. It would still let the program compile since it's still a valid statement; assignment returns a value, so the if statement evaluates that value. But now I'm curious about whether "if (func())" would be an error if func were void.
Alright, I need some help here. I'm new to C++, only on the 47th page of my first book, and I don't exactly get what this does. I somewhat get vectors, I know what most of it means, but I need someone to thoroughly explain it to me, a newbie.
[code]#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
using std::cin; using std::sort;
using std::cout; using std::streamsize;
using std::endl; using std::string;
using std::setprecision; using std::vector
int main()
{
// ask for and read the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
//ask for and read the midterm and final grades
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;
// ask for and read the homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
vector<double> homework;
double x;
// invariant: homework contains all the homework grades read so far
while (cin >> x);
homework.push_back(x) ;
// check that the student entered some homework grades
typedef vector<double>::size_type vec_sz;
vec_sz size = homework.size();
if (size == 0) {
cout << endl << "You must enter your grades. "
"Please try again." << endl;
return 1;
}
// sort out the grades
sort (homework.begin(), homework.end());
// compute the median homework grade
vec_sz mid = size/2;
double emdian;
media = size % 2 == 0 ? (homework[mid] + homework[mid=1]) / 2
: homework[mid];
// compute and write the final grade
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * median
<< setprecision(prec) << endl;
return 0
}
[/code]
[QUOTE=ROBO_DONUT;24952090][cpp]
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
int addflag = 0;
for (int i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-add") == 0) {
addflag = 1;
break;
}
}
if (addflag) {
/* add values and print here */
}
}
[/cpp]
:ninja:[/QUOTE]
I tried running your code and:
[code]main.c: In function ‘main’:
main.c:8: error: ‘for’ loop initial declaration used outside C99 mode
main.c:19: warning: control reaches end of non-void function
make: *** [main] Error 1[/code]
you need to compile in c99 mode
It would be an error because the if needs an input.
[cpp]if(returnVoid()) doStuff();
if() doStuff();[/cpp]
I believe those would essentially be the same although you'd probably get a different compiler error.
[QUOTE=Zally13;24953047]Alright, I need some help here. I'm new to C++, only on the 47th page of my first book, and I don't exactly get what this does. I somewhat get vectors, I know what most of it means, but I need someone to thoroughly explain it to me, a newbie.
[code]#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
using std::cin; using std::sort;
using std::cout; using std::streamsize;
using std::endl; using std::string;
using std::setprecision; using std::vector
int main()
{
// ask for and read the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
//ask for and read the midterm and final grades
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;
// ask for and read the homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
vector<double> homework;
double x;
// invariant: homework contains all the homework grades read so far
while (cin >> x);
homework.push_back(x) ;
// check that the student entered some homework grades
typedef vector<double>::size_type vec_sz;
vec_sz size = homework.size();
if (size == 0) {
cout << endl << "You must enter your grades. "
"Please try again." << endl;
return 1;
}
// sort out the grades
sort (homework.begin(), homework.end());
// compute the median homework grade
vec_sz mid = size/2;
double emdian;
media = size % 2 == 0 ? (homework[mid] + homework[mid=1]) / 2
: homework[mid];
// compute and write the final grade
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * median
<< setprecision(prec) << endl;
return 0
}
[/code][/QUOTE]
Bump because of new page.
[QUOTE=Sonicfan574;24953139]I tried running your code and:
[code]main.c: In function ‘main’:
main.c:8: error: ‘for’ loop initial declaration used outside C99 mode
main.c:19: warning: control reaches end of non-void function
make: *** [main] Error 1[/code][/QUOTE]
Invoke gcc with "-std=c99".
If you want to stick with c89, then you can do:
[code]
int i;
for (i=0; i<argc; i++) {
[/code]
edit: got super ninja'd
[QUOTE=Zally13;24953306]Bump because of new page.[/QUOTE]
You should probably post the lines that are confusing and why they are confusing you. Try rereading the chapter.
[QUOTE=Pepin;24953700]You should probably post the lines that are confusing and why they are confusing you. Try rereading the chapter.[/QUOTE]
It seems it's not compiling, how do I check/change what compiler I'm using with Code::Blocks?
[QUOTE=Zally13;24954385]It seems it's not compiling, how do I check/change what compiler I'm using with Code::Blocks?[/QUOTE]
Code::Blocks defaults to MinGW.
How in SDL.net would I allow a surface to use png transperecy and then is there any difference in drawing or do I just use Blit.
Sorry, you need to Log In to post a reply to this thread.