DeanMSands3 69 Junior Poster

This post is effectively solved and needs to be marked as such, but for the reference of anyone coming along later, here's what happened:
The sin_addr contains a 32-bit unsigned long int. Not a string. 127.0.0.1 as a number would look like 0x7F000001 or 2130706433 in decimal. The numbers 49, 50, 55, 46 are the ASCII codes for '1', '2', '7', and '.' respectively. A memcpy would do a byte for byte copy of the string "127.0.0.1". I feel sorry for whoever's at 49.50.55.46. They must get this all the time.

Instead you need to use inet_pton (inet_aton is now deprecated).
For a more in-depth look at sockets, have a look at the venerated Beej's Guide to Network Programming.

When Chuck Norris wants to roundhouse kick a browser into existence, he asks Beej for advice first.

DeanMSands3 69 Junior Poster

Not a morning person? Get a cat.

DeanMSands3 69 Junior Poster

If you were me, you'd be married to the greatest woman on earth.

codeorder commented: (:.respectable.:) +0
DeanMSands3 69 Junior Poster

OK, so I wrote the test case.
Not good, my friends. Not good.

The scaling doesn't work and it still tries to print even if the printer is unable.
I'll research this further.

DeanMSands3 69 Junior Poster

Ditto was made using Visual Studio, so it's probably best to use Visual Studio to edit it.
You'll want Visual C++ Express since its free to use (I'm pretty sure that Express version will do what you need).
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

Also, it may be helpful to read up on the extra libraries used: TinyXML, SQLite, and zLib in addition to their custom EncryptDecrypt library.
http://www.grinninglizard.com/tinyxml2/index.html
http://www.sqlite.org/
http://zlib.net/
I also recommend researching InnoSetup as that's what Ditto uses.
www.jrsoftware.org/

(translation: Read all the Friendly Manuals or Narue will come for you in the night.)

DeanMSands3 69 Junior Poster

tl;dr: I think my code sucks. Can you help me?

I haven't written a test case for this class yet, but I want to make sure I'm doing it right before I go home tonight.
The gist of the class is to provide a reusable ImagePrinter object that can print a scaled bitmap to the default printer without prompting the user, but still ensuring that the printer is OK to print to. Admittedly, it's a hodge-podge of code segments I've dug up from parts of the web and I only know that certain parts of it will work. printIfOK is the function that gets the ball rolling after the object has been instantiated.
So yeah. I'm probably doing wrong. Show me some love, will ya, DaniWeb?

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Printing;
using System.IO;

namespace ScreenGrabber
{
    /// <summary>
    /// Prints creates a reusable object that prints a scaled image to the default printer.
    /// </summary>
    public class ImagePrinter
    {
        private Image source=null;
        private PrintServer localPrintServer=null;
        private PrintQueue  defaultPrintQueue=null;
        public ImagePrinter()
        {
            setupPrintServerAndQueue();
        }
        private void setupPrintServerAndQueue(){
            localPrintServer = new LocalPrintServer();
            defaultPrintQueue=getDefaultPrintQueue();
        }
        private bool OKtoPrint(){
            if(isPrintQueueOK()){

                return true;
            }else{
                return false;
            }
        }
        private PrintQueue getDefaultPrintQueue(){

            PrintQueue pq=null;
            // Retrieving collection of local printer on user machine
            PrintQueueCollection localPrinterCollection =
                localPrintServer.GetPrintQueues();

            System.Collections.IEnumerator localPrinterEnumerator =
                localPrinterCollection.GetEnumerator();

            if (localPrinterEnumerator.MoveNext())
            {
                // Get PrintQueue from first available printer
                pq = (PrintQueue)localPrinterEnumerator.Current;
            }

            return pq;

        }
        private bool isPrintQueueOK(){
            if(defaultPrintQueue==null)
                return false;
            if (defaultPrintQueue.HasPaperProblem)
            {
                return …
DeanMSands3 69 Junior Poster

A true Nihilist knows he has Nothing to look forward to and does so with great anticipation.

DeanMSands3 69 Junior Poster

Today, I decided to poison my imaginary friends. It worked wonderfully until I realized that one of the bodies wasn't imaginary.
-DMS3

DeanMSands3 69 Junior Poster

Yes, apparently number 4 works. That only took my entire day to find.

Facepalm.

DeanMSands3 69 Junior Poster

I've got a program I'm writing that
A. runs as a service
B. grabs a screenshot of a specific window every X number of seconds
C. prints it to the default printer.

A and B are more or less done.
C is confusing me.

I'm looking for a way to print without the PrintDialog coming up. If you can help, that'd be swell.

As best I can tell, my options are:
1. P/Invoke it with Win32 calls. Eh, sure, I guess.
2. Intercept the PrintDialog Eh, no.
3. Printing in an embeddable browser. Not the minimal overhead I was looking for.
4. doc.PrintController = new StandardPrintController(); //I have no idea if that actually works. I'm about to test it.

DeanMSands3 69 Junior Poster

My imaginary friends talk about me like I'm not even here.
-DMS3

DeanMSands3 69 Junior Poster

My imaginary friends tell me not to hurt myself or others.
But my doctor says I can ignore them.
-DMS3

DeanMSands3 69 Junior Poster

I've been quite lonely since my imaginary friends stopped playing with me.
-DMS3

DeanMSands3 69 Junior Poster

“You know," said Arthur, "it's at times like this, when I'm trapped in a Vogon airlock with a man from Betelgeuse, and about to die of asphyxiation in deep space that I really wish I'd listened to what my mother told me when I was young."
"Why, what did she tell you?"
"I don't know, I didn't listen.”
-Douglas Adams, Hitchhiker's Guide to the Galaxy

DeanMSands3 69 Junior Poster

Hm... for the moment, I'm going to say I was wrong about everything and leave it at that.
I'm still looking over the assembly (and I'm very rusty with GNU assembler), but being as my job expects me to produce results before the end of the day, I probably need to put this away for now.

Happy coding all.

DeanMSands3 69 Junior Poster

@Sokurenko: I'm not the kind of guy who down-votes posts willy-nilly (unless you're being condescending and a complete ass), but your post is... not what the OP is asking for. Pass by value, not reference. Yours is reference. Granted, your code is instructive to new coders and you're not rude, so no down-voting.

@Deceptikon: Back in the days of Turbo C, I remember folks saying never put an array in the arguments, and instead use its pointer AND the same thing about struct's. Back then, passing by value would obliterate the then-miniscule memory stack like no tomorrow. I'm tempted to say that if you pass an array of specific size to a function expecting a specific size, it will pass by value, but I don't know. I'll compile some code as small as I can get it and read the assembly to see. Of course, that'll only prove one compiler for one platform. Meh.

As an aside, in some countries the days of Turbo C seem to be today, tomorrow, and the day after that.

DeanMSands3 69 Junior Poster

MeetingsMotivator

Next word: Programming

DeanMSands3 69 Junior Poster

The rules of this game is simple:
1. Someone posts a word.
2. You make a (de)motivational picture out of it.
3. You post the picture and a new word for the next poster.
4. The base image can belong to anyone, but the completed captioned product must be yours.

Allow me to demonstrate.

Meetings

DeanMSands3 69 Junior Poster

In Line 4, you're allocating a char buffer and assigning it to TempString.
And you need to add 1 to account for the trailing zero. strlen will only get the non-zero characters.
In Line 5, you're assigning String to TempString, overwriting the pointer to the buffer you'd just created. Um...why?
That buffer is gone and you can't get it back.
The rest of it I'm too lazy to check, though it looks like it would work though not the way I'd do it.
Have a look at strstr. It does a body good.

int i=0;
int j=0;
char      *TempString;
TempString = (char*)malloc((strlen(String)+1)*sizeof(char));
//TempString = String;
    while(String[i])
    {
        if((String[i] == '1') && (String[i+1] == '2')) // Deleting string "123" 
        {   
            while(String[i] != '3')
                i++;
            i++;
            flagcount++;
        }
        TempString[j] = String[i];//its crashing here while debugging.
        i++; j++;
    }
    TempString[j]=0;    
DeanMSands3 69 Junior Poster

I'm going to go into pedantic mode for a bit. Apologies if either of you are offended in the process.

And here I thought I was being the insufferable troll. ;)

DeanMSands3 69 Junior Poster

You are what you eat. And so, if we feel that you're being a(n) ____ , well, we all know what you had for breakfast.

ChrisHunter commented: Funny post, made me laugh +0
DeanMSands3 69 Junior Poster

Oh hey. Did you go somewhere? I hadn't noticed. ;)

DeanMSands3 69 Junior Poster

I'm not entirely sure I understand the rules of the game. Could you explain further?

DeanMSands3 69 Junior Poster

Also, here's an instructional video from Stanford on using Pointers.
Stanford Explains Pointers
I'm putting this as a second post as my first post deserves an up-vote while this post, despite its clearly educational value, will brand me as an insufferable troll.
And I probably deserve that.
Enjoy!

DeanMSands3 69 Junior Poster

OK. This is a common problem for beginners. You have a pointer (*a). This pointer points to nothing.
You do a scanf into the pointer. The program has an aneurysm. The stock market collapses! Puppies and kittens around the world suddenly vanish!
Heh. So yeah. *a needs something to point to.

Try one of the following:
1: Using an array.

#include <stdio.h>
#include <conio.h>

void main()
{
    char a[101];

    printf("Enter the string: ");
    scanf("%s",&a); //You can keep the ampersand, but you don't need it here.

    printf("\nEntered string is :%s", a);
    getch();
}

2: Allocating a buffer.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
    char *a;
    a=(char*)malloc(101*sizeof(char));
    printf("Enter the string: ");
    scanf("%s",a);  // You definitely don't want the ampersand here.
                    //That'd be a pointer to a pointer

    printf("\nEntered string is :%s", a);
    getch();
    free(a);
}

Now, why did I use 101 as my size? C needs a zero terminator at the end of its strings, so you have to allocate +1 more than the size you want.

Perry31 commented: Thanks for prompt reply.. +0
DeanMSands3 69 Junior Poster

OK. Let's see your code.

DeanMSands3 69 Junior Poster

Ah, good catch there. I didn't notice that.

DeanMSands3 69 Junior Poster

I doubt I'm fully aware of what webkit is and does, but can't you just use dotnet for this type of thing?

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx

Or if you still want to use WebKit, you can use:
http://webkitdotnet.sourceforge.net/

DeanMSands3 69 Junior Poster
indices = malloc (sizeof(short) * data.face_count * 3);
for (i = 0; i < data.face_count; i += 3);
{
    indices[3 * i]     = data.face_list[i]->vertex_index[0];
    indices[3 * i + 1] = data.face_list[i]->vertex_index[1];
    indices[3 * i + 2] = data.face_list[i]->vertex_index[2];
}

Multiply i by 3. Try it. You'll like it.

DeanMSands3 69 Junior Poster

Webkit is the browsing engine used by Safari and Chrome. It's open source and cross platform.

@OP: If you really really want WebKit, you could try using the QtWebKit port.

DeanMSands3 69 Junior Poster

Last day, I had the weirdest daymare. I dreamed there was a clown and a giant rabbit and they were going to eat me alive and I only had an accordion to -

Why are you laughing?

DeanMSands3 69 Junior Poster

The logarithm of x in relation to 42 where x is the asking person's phone number.
If I invite 7 people to dinner at a fancy bistro, 9 actually come, and I show up 30 minutes late, should I order the chicken fetuccini alfredo?

DeanMSands3 69 Junior Poster

Put in checkpoints in your code like printf("Client: Now entering client function.");

Tell us what happens.

DeanMSands3 69 Junior Poster

So long as I remain silent, I will continue to suffer.

DeanMSands3 69 Junior Poster

Too hot for

DeanMSands3 69 Junior Poster

The proper multiplication of 6 times 9 and how it relates to 42.

If Ann leaves her house in Schaumburg at 7:05 AM and drives to the O'Hare International Airport in Chicago, and immediately takes the first flight to Denver, how many passengers on board will know Douglas Adams references?

DeanMSands3 69 Junior Poster

Vice

DeanMSands3 69 Junior Poster

What OS are you using? It makes a difference.

Also, if you're looking to do a git like command, are you familiar with socket programming?

Next, if you're connecting to a remote server (the way git does) how is the server going to handle your request and in what language?

Lastly, if so, do you have a server you can use?

DeanMSands3 69 Junior Poster

Here's the GetLastError function.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx
Send it out to the command line.

Then look it up here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

Tell us what's killing it.

DeanMSands3 69 Junior Poster

Use the dynamically linked glew32.
Reference:
http://forums.codeblocks.org/index.php?topic=13055.0;wap2

I also included a picture showing that what settings I'm using in Eclipse. I don't have NetBeans on this system. ProjectSettings

This is a picture of a Smurf swimming in a lake.
Smurf

DeanMSands3 69 Junior Poster

OK, the #pragma bit doesn't factor in with MinGW. You've got to tell the linker what you're using.
You'll need to go to Project Properties and Linker settings. I can't remember the exact location so lmgtfy:
http://lmgtfy.com/?q=netbeans+C%2B%2B+linker+libraries
You need to link in glew32, opengl32, and gdi32 - in that order.
Make sure to do that for both Debug and Release.

Make sure that the glew32.dll is somewhere in your system path. (It's in the lib folder, but that probably won't work. I copied mine to the bin folder.) Otherwise, your program will croak prematurely.

Also, I compiled and ran the program. It's blue. That's it. That's the great smurfing mystery. It's Microsmurf Cornflower blue. That's all there is.

DeanMSands3 69 Junior Poster

Lines 24 and 26.
You've got a for loop variable i going from 0 to 9. You've got a comparison between score[i] and score[i+1]
When i hits 9, that's a comparison between score[9] and score[10].
Silly question for the day: Does score[10] exist?

Happy coding.
-dean

DeanMSands3 69 Junior Poster

Let's start with the I'm a C guy, but this C++ stuff sounds really neat approach:

#include <iostream>
#include <string>
#include <cmath>
//#include <math.h>  //Don't need this if you have cmath.
#include <algorithm>

using namespace std;

int main()
{
    int number_of_students, i;
    string dummy, *student_name; //Declare student_name as a pointer
    cout << "how many students do you have? ";
    cin >> number_of_students;
    getline(cin,dummy); //Flushes dangling new-line. Needed later for getline.
    cout << endl;

    //string *student_name =new string[number_of_students];
    student_name =new string[number_of_students]; //Allocate student_name with new[]
    for(i=0;i<number_of_students;i++){
        cout<<"Enter name of student["<<(i+1)<<"]: "; //Using i+1 because no one wants to be student[0]
        getline(cin,student_name[i]);
    }

    cout<<"These are the students.\n";
    for(i=0;i<number_of_students;i++){
        cout<<"Student["<<(i+1)<<"]: "<<student_name[i]<<endl;
    }

    delete student_name; //Free memory allocated by student_name.

    //Some DaniWeb veterans get very vehement when you use system("pause");
    cout<<"Please press Enter to exit...";
    getline(cin,temp);  //Flushes dangling new-line.

    return 0;
}

And, as far as C++ is concerned, this is the wrong way even though its correct.
Let's get to actual Standard Template Library stuff.

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int number_of_students, i;
    string temp; //Actually a very cool STL data structure, but doesn't get the respect it deserves.
    vector<string>student_name; //Now we're cooking with STL!
    cout << "how many students do you have? ";
    cin >> number_of_students;
    cout << endl;

    getline(cin,temp);  //Flushes dangling new-line.
    for(i=0;i<number_of_students;i++){
        cout<<"Enter name of student["<<(i+1)<<"]: ";
        getline(cin,temp);
        student_name.push_back(temp); //Adds the student's name to the list
    }

    cout<<"These are the students.\n";
    for(i=0;i<number_of_students;i++){
        cout<<"Student["<<(i+1)<<"]: "<<student_name[i]<<endl;
    } …
DeanMSands3 69 Junior Poster

Are you trying to read XML?
I wouldn't use RegEx for it.

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

I use TinyXML2. It's pretty simple once you get the hang of it.
http://www.grinninglizard.com/tinyxml2/index.html

DeanMSands3 69 Junior Poster

Uh... hm...
It's... um... astonishingly easy. If you've ever used MSYS. Which you probably haven't.

OK, so assume I have a full MinGW and MSYS install.
I download the source file (at https://sourceforge.net/projects/glew/files/glew/1.7.0/glew-1.7.0.tgz/download ) to my C:\Workspace\Source folder.

I open MSYS which takes me to a command-line. I change to the C:\Workspace\Source folder.
cd /c/Workspace/Source
I unzip the tar-ball.
tar -xzf glew-1.7.0.tgz
I change to the glew-1.7.0 folder.
cd glew-1.7.0

I openthe Makefile in Wordpad (formerly called Write).
write Makefile
I scroll down a few pages until I see:
GLEW_DEST ?= /usr
I change it to:
GLEW_DEST ?= /mingw
I save and close Wordpad.

I run the Makefile with the make program. This compiles the binaries.
make

Then, when it finishes,
make install
This copies the binaries and header files where the compiler can use them.

It's ready to rock.

DeanMSands3 69 Junior Poster

The Visual Studio libraries probably aren't going to work for MinGW (what Dev C++ compiles with).
MinGW = Minimal GNU for Windows.

And Dev C++ is kind of dead anyway.

Get a full MinGW installation (GCC & G++) with at least a minimal MSYS that has Make.
Then get Eclipse or NetBeans as your IDE. (NetBeans, at least for me, has always felt "friendlier.")

Meanwhile, I'm going to see if I can get Glew built for MinGW.

DeanMSands3 69 Junior Poster

I remember some code Mike Abrash had written that (I believe) found its way onto x2ftp. IIRC (If I recall correctly), he used K&R with 3-space indents. I guess when you're Mike frickin' Abrash you can pull quirky stunts like that.

EDIT: I stand corrected. He used Allman. But, yes, his XSharp 3D package v22 from way back in 1992 was written with 3-space C files - BUT the ASM files were written with full tabs.
Link: ftp://ftp.lanet.lv/pub/programming/mirror-x2ftp/source/xsharp22.zip

DeanMSands3 69 Junior Poster

Start with a simple program.

#include <stdio.h>

int main(){
    printf("Hello World!");
    return 0;
}

Then expand on it.

#include <stdio.h>
char name[20]="firdousahmad";
int main(){
    printf("Hello World!\n"); //The backslashed n starts a new line.
    printf("My name is %s.", name); //printf will replace the %s with the "name" variable.
    return 0;
}

Get silly with it.

#include <stdio.h>
    char name[20]="firdousahmad";
    int main(){
    int i;
        printf("Hello World!\n"); //The backslashed n starts a new line.
        printf("My name is %s", name); //printf will replace the %s with the "name" variable.
        for(i=0;i<10;i++){
            printf("!");
        }
        return 0;
    }

Then get even sillier.

#include <stdio.h>
char name[20]="firdousahmad";
int main(){
    int i, x, y;
    printf("Hello World!\n"); //The backslashed n starts a new line.
    printf("My name is %s", name); //printf will replace the %s with the "name" variable.
    for(i=0;i<10;i++){
        printf("!");
    }
    printf("I have a strange obsession with triangles.\n");
    for(x=0;x<10;x++){
        for(y=0;y<=x;y++){
            printf("*");
        }
        printf("\n");
    }
    printf("It's really sort of tragic.\n");
    return 0;
}

Have fun. Learn. Be silly. Enjoy it.
Happy coding.

DeanMSands3 69 Junior Poster

The h after the number means that's it's in hexadecimal.

Hexadecimal numbers run from 0-9A-F. Each digit is multiplied by a power of 16. So 57h is 5 * 16^1 + 7 * 16^0.

You can also use the 0x prefix to denote hexadecimal. So 57h is the same as 0x57.

Hexadecimal can be useful in ASCII as numbers begin with 0x30 (48d) or '0' and go to 0x39 (57d) or '9'.

Also, the letters of the alphabet are offset by 0x40 (64d) for uppercase and 0x60 for lowercase. So, 'A' is 0x41, 'B' is 0x42, 'C' is 0x43, etc. up to 'Z' which is 0x5A.

DeanMSands3 69 Junior Poster