gusano79 247 Posting Shark

Matching the file names doesn't replace the file name itself. You can still use the standard io library to read the files:

for entry in lfs.dir(folder) do
    if string.match(entry, pattern) ~= nil then
	local file = io.open(entry, "r")

	-- TODO: Read stuff from the file here.

        file:close()
    end
end
gusano79 247 Posting Shark

so instead of file:lines() i can just put this ? and this will allow my text output be created?

The example I posted is just to decide whether the file name ends with ".bmp" or whatever other pattern you want to detect. You'll still have to read the contents of the file and do whatever it is you want to do with it. It's more of a replacement for if #dir_elem > 4 and dir_elem:sub(#dir_elem-3, #dir_elem) == ".obj" . IMO, the pattern is easier to read.

But maybe I misunderstood the question... file:lines() doesn't take any parameters. You can use pattern matching on the lines it returns, though. Something like:

for line in file:lines() do
    if string.match(line, "v") then
        --Writes GL_Vertex3f for every occurence of v
        input:write(" GL_Vertex3f ")
    end
end

Depending on what you're trying to do, the pattern might be different, but that's the basic idea.

gusano79 247 Posting Shark

i have made a program with this algorithm but its not working properly my code is given below can you help me to remove the errors

There's only one compiler error: You can't call getch with any parameters, like you are when you say getch(f) . The only call you can make is getch() . But the real error is that you can't use getch to read from files. You probably want fgetc instead.

Other problems that you should correct: void main() isn't proper C; it should be int main() --with a matching return at the end, of course. if(f != 'NULL') is wrong. NULL isn't a character constant, it's a symbol defined in stddef.h . You meant if(f != NULL) . while(ch = fgetc(f) != EOF) is potentially confusing. You might want to write while((ch = fgetc(f)) != EOF) , which makes it clear that you're comparing the result of the assignment with EOF , instead of assigning a truth value.

gusano79 247 Posting Shark

Looks like you're not linking the pthreads library. You'll need to add a reference to the library to your project. If the FAQ I linked doesn't work for you, look for something similar in the project settings--perhaps someone who is familiar with CDT (i.e., not me :)) knows where to find it.

gusano79 247 Posting Shark

If you're going to use the << and >> streaming operators, you need to define their behavior--the compiler can't decide what you want them to mean.

For example:

void Result()
    {
        cout << "\nThe matrix " << Size << "by" << Size << "\n" << this << "is:\n";
        cout << "Reflexive: " << (Reflexive() ? "" : "NO ") << "Yes\n";
        cout << "Symmetric: " << (Symmetric() ? "" : "NO ") << "Yes\n";
        cout << "AntiSymmetric: " << (Antisymmetric() ? "" : "NO ") << "Yes\n";
        cout << "Transitive: " << (Transitive() ? "" : "NO ") << "Yes\n";
    }

    ostream& operator<< (ostream& out)
    {
        return out << Size; // Change this to output whatever you want
    }

Note that if you make the operator part of the class, you don't need to dereference this (line 3 in the example).

A similar operator definition is needed for >> that reads from an istream .

Also, what compiler are you using? GCC flags additional errors... you don't need to say something like bool Binary::Reflexive() if you're providing function bodies in the class definition; you can just use bool Reflexive()

gusano79 247 Posting Shark

It doesn't say anything to the CPU; this directive doesn't generate any code. It's only there to help the assembler. Here's an article that goes into some detail with a few examples.

gusano79 247 Posting Shark

lfs.dir returns each directory entry's name as a string, so you can use string.match from the standard library to detect file name patterns.

Here's a simple example:

filename = "test.bmp"

pattern = "\.bmp$"
if string.match(filename, pattern) ~= nil then
	print(filename)
else
	print("NO MATCH")
end
gusano79 247 Posting Shark

You can use the UTF8Encoding and UTF32Encoding classes to encode and decode text.

gusano79 247 Posting Shark

When the recursion started by the line call Factorial returns, execution continues at the line labeled with ReturnFact .

Note that this only happens when recursive calls are made; if the line jmp L2 is executed (i.e., it's time to terminate the recursion), the code at ReturnFact is skipped.

gusano79 247 Posting Shark

You may also want to consider PNG.

gusano79 247 Posting Shark

Thanks for your reply, but you might misunderstood my question. There are two questions. First of them is " Which methodology would you use for that system?" The other one is to about data flow diagrams.

Oh, sorry, I read that as a single question. It does make more sense as two :)

Are you able to share a more detailed description of the system you're designing? In particular, what activities are you monitoring, and how often? Is there a reporting requirement? For both the data flow and development methodology questions, a lot can depend on the requirements you have (or sometimes, don't have). Also, do you have any scheduling constraints--i.e., how much of it do you have to deliver, and when?

gusano79 247 Posting Shark

Sounds like you mean a list of all the predefined colors, like Color.Violet, yes? You could use reflection to determine all of the static properties of the Color class that have a property type of Color themselves. Do you know how to do that?

gusano79 247 Posting Shark

A data flow diagram describes certain aspects of the design of a system. "Waterfall" is a software development methodology, which describes the process by which the system is built. I think you're comparing apples and oranges here. No matter what development methodology you use, you'll be able to create a DFD to describe your product.

gusano79 247 Posting Shark

So here is the problem, I cant figure out what have I done wrong, I'd appreciate any help given.

Please use CODE tags and indent your code; this will make it easier for us to read.

Also, it helps if you tell us what "wrong" means--what are you expecting to happen, and how is what's actually happening different?

At a first glance, this code looks suspicious:

for(int i = 2; i <= c; i++)
{
    while(c % i == 0)
    {
        c /= i;
        icount++;
    }
}

It looks like you're counting the number of prime factors, not the total number of digits across all prime factors, &c.

gusano79 247 Posting Shark

I'm trying to make it where I can draw an square with the values in the global array. I made it work without vertex array before but now I need to save it in array so I can possibly delete a square with just a mouse click. However I can't get the squares to show up on screen, it just appears blank. Any suggestions?

Have you checked your compiler warnings? Using GCC, I'm getting two:

  1. In function 'GLPoint mid(GLPoint, GLPoint)':
    warning: left-hand operand of comma has no effect
    GLPoint mid(GLPoint A, GLPoint B)
    {
        GLPoint midpt = (GLPoint) {
            ((A.x + B.x) / 2, (A.y + B.y) / 2)
        };
        return midpt;
    }

    Try removing the outer brackets: (A.x + B.x) / 2, (A.y + B.y) / 2

  2. In function 'void myMouse(int, int, int, int)':
    warning: statement has no effect
    if(state == GLUT_DOWN)
    {
        if(button == GLUT_LEFT_BUTTON)
        {
            for(int j = 0; j < totalmarbles; j++)
            {
                if(hitbox[j] < 100)
                {
                    vertices[63];
                    drawrectangles();
                }
            }
        }
    }

    What are you trying to do with that line?

gusano79 247 Posting Shark

I'm not familiar with the book, but I expect that it still has a lot of good information. In particular, anything it has to say about the concepts behind games, like object modeling, rendering, AI, &c. should still be relevant.

If the book is strictly win32 API, I imagine you're stuck with GDI and PlaySound. These are fine for learning; you'll pick up concepts that apply more generally.

You're going to run into limitations, though, especially in the graphics and sound department. For more complicated multimedia, you'll want something more powerful, like DirectX, or OpenGL and OpenAL if you want to target more than just Windows machines.

gusano79 247 Posting Shark

That only found the first number in the equation, how do I make it find the second one, etc?

Splitting the string (directly or by regex) is a little tricky, and the code quickly gets tedious and ugly.

Below is an attempt at a regular expression that gets the sign right. I'm giving this to you on the condition that you only use it if you understand it, i.e., you should know what everything in that regex is and what it does.

using System;
using System.Text.RegularExpressions;

class Program
{
    public static void Main(string[] args)
    {
        RegexTest("(1+2j)*(3-4j)= 11+2j");
        Console.ReadKey(true);
    }
    
    static readonly Regex regex = new Regex(
        @"^\((?<a_real>[+-]?\d+(\.\d+)?)(?<a_imag>[+-]\d+(\.\d+)?)j\)\*\((?<b_real>[+-]?\d+(\.\d+)?)(?<b_imag>[+-]\d+(\.\d+)?)j\)",
        RegexOptions.ExplicitCapture |
        RegexOptions.Singleline);
    
    static void RegexTest(string equation)
    {
        Match m = regex.Match(equation);
        
        if(m.Success)
        {
            double ar = Double.Parse(m.Groups["a_real"].Value);
            double ai = Double.Parse(m.Groups["a_imag"].Value);
            double br = Double.Parse(m.Groups["b_real"].Value);
            double bi = Double.Parse(m.Groups["b_imag"].Value);
            
            Console.WriteLine("a.real = {0}", ar);
            Console.WriteLine("a.imag = {0}", ai);
            Console.WriteLine("b.real = {0}", br);
            Console.WriteLine("b.imag = {0}", bi);
        }
        else
        {
            Console.WriteLine("Couldn't match '{0}'", equation);
        }
    }
}
gusano79 247 Posting Shark

Hello everyone,

I'm a java programmer writing a half graphical half text rpg. For the moment I read my data from text files, e.g.
Enemies.txt

id
name
hp

and so forth. However, I want to make it a little more clear to handle, as in a database format. I can work with MySQL, but I want all the data to be on the end-user's computer, so without having to connect to the server database.

The only other thing I can think of is Excel, but I'm wondering if there aren't any other alternatives. If you know how real games used to do it, it would be really helpful.

I'd avoid Excel; that's a nightmare waiting to happen.

A proper database might be overkill, though, especially if your data are simple. Does "clear to handle" mean you want it to be human-readable and editable, or are you referring to making it easier for your code to load stuff in? Or is it a balance of the two?

As a step up from plain text, XML might be a good choice for you. It's structured and well-supported by standard libraries, so it helps the machines, but it's also still text, so it's still easy enough to edit by hand.

JSON is another option for text-based structured data.

If you really want a local-only database, I recommend SQLite. It's been widely adopted for use by Web applications and in embedded …

gusano79 247 Posting Shark

Thanks for the reply .
Do we have any reference operators in C that I can replace with ?

C doesn't have the reference operator at all. You can change the three output parameters to pointers, much like the rotation function does. For example: float* x1 . You'll also have to update the body of the function to dereference these parameters when you want to use their values: *z1 = tantheta * *x1; . Then any code that calls the function needs to explicitly take the reference of the output parameters as well: polar_to_cartesian(azimuth, length, altitude, x1, y1, z1) becomes polar_to_cartesian(azimuth, length, altitude, &x1, &y1, &z1) .

gusano79 247 Posting Shark

Hi I am trying to run this C code in Visual Studio along with a set of Cpp files.
It gives the below errors
error 2143 : syntax error : missing ')' before '&'
error 2143 : syntax error : missing '{' before '&'
error 2059 : syntax error : '&'
error 2059 : syntax error : ')'

and the error is at
<< void polar_to_cartesian(float azimuth, float length, float altitude, float&x1, float&y1, float&z1) >>

I am not sure why this is popping up as all my declarations are correct .
Please help me in resolving this

You're trying to compile C++ code as C, so the compiler barfs. The reference operator ( & ) only exists in C++.

gusano79 247 Posting Shark

Do you have a question you want answered? I don't see one.

"he is noob"? Really?

From what you posted, I can see at least three possible questions you might have about autocomplete for C/C++ in VS2010, but it's not clear what you're asking. I could take a guess, but odds are I'll pick the wrong one, and we'll waste your time and mine posting back and forth about it. Instead, how about you take a minute to formulate an actual question--that way, someone reading it can attempt an answer with confidence that nobody's time is being wasted. That is the kind of post that gets responses.

gusano79 247 Posting Shark

Do you have a question you want answered? I don't see one.

Panathinaikos22 commented: he is noob +0
gusano79 247 Posting Shark

A bit of clarification: In a single-threaded application, the main thread handles updating the forms and other user interface elements. If you simply put a long-running task in a button's click handler, the main thread stays busy there, and doesn't get a chance to update the UI until it's done. This is why you can't do anything on the form once it starts. When you call DoEvents on the main thread, it processes any pending messages to the application, so the UI remains responsive. The trick is you have to call it repeatedly while your task is running.

So. You could sprinkle your "start" task with calls to DoEvents, have the "abort" handler set some Boolean variable when clicked, and have your "start" task check this variable periodically and stop when it's set.

If you search the Internet, you'll find a variety of opinions about DoEvents. Here's mine: It's fine for simple tasks you want to happen in the main thread, and lets you avoid the complexity of multithreading. As your tasks get longer and more involved, though, it can get ugly.

I don't use DoEvents, and I don't recommend it to anyone, either. Instead, consider the BackgroundWorker class. All you have to do is add an event handler to do your work, and this class takes care of the multithreading for you. To abort, you would use the CancelAsync method; your "do work" event handler has to check the

nick.crane commented: Exactly what I do. +10
gusano79 247 Posting Shark

The errors that I am still getting are the invalid id message is printing for every invalid data even if the id is correct. The grades are not printing out correctly either, every grade is a F. Also the grade counters are not working at all either they are giving random numbers like 0 41976350 -44000068032767. I was wondering what needs to be done to correct these things, I have done everything that I can think of/know how to do.

Sounds like you've made some changes; we'll need to see them to help with what's left... please post the updated files. Maybe as attachments this time; it's easier for us than copying/pasting everything.

gusano79 247 Posting Shark

My program is compiling fine but my issue is with the output. The grades are not correct and the counters are not working either.

You'll get more help if you tell us what grades you expect to see, not just that they're "not correct." What output are you expecting? But first, what input are you feeding your program? It's looking for " in.data " but you haven't included that here.

The code is not "compiling fine," at least using GCC. I see three warnings in my compiler output; they all indicate areas in your code that need some attention. Always, always pay attention to your compiler warnings; they usually point at something weird going on.

In extStud.cxx, extStudType::findGrade :

grade == 'A';

I'm sure you meant grade = 'A'; there.

In stud.cxx : Both findMax and findMin don't always return a value. Look at your if / else statements; do you see why?

Also, in findMax :

if((exam1 || exam2 || exam3) > max)

This is not how to use an if statement to test multiple conditions. Try this:

if((exam1 > max) || (exam2 > max) || (exam3 > max))

Same goes for findMin .

gusano79 247 Posting Shark

I see that you're still processing the string directly; what I meant is load this string into an XmlDocument. Then you can use methods on the document like SelectNodes and SelectSingleNode to do XPath queries on the document, which would make your code much shorter and easier to read and understand.

If you post a complete XHTML result--as a file, please, not in a code block--I can post a few sample XPath queries to get you started.

gusano79 247 Posting Shark

Hm. You might be accidentally indexing outside of the bounds of one of your arrays. It sounds odd that it would just stop working... is this a release build? I'd expect to see some sort of exception message. Are you running it from within an IDE?

gusano79 247 Posting Shark

It looks like you need to use the ProcessStartInfo class. The CreateNoWindow property should be useful.

gusano79 247 Posting Shark

To me, the most easily answerable posts contain the shortest possible amount of code that is complete (meaning I don't have to add anything to get it to compile and run), and still demonstrates the issue/concept you're asking about.

In my experience, just going through the process of isolating my problem to a minimal amount of code often makes it pretty clear what the problem really is.

gusano79 247 Posting Shark

the program does what you want it to do so it can't be all that bad.

I'm going to assume that was sarcastic--otherwise, you need to have a serious talk with anyone who has to actually maintain code.

:)

gusano79 247 Posting Shark

This is your problem:

void putvalue(X a)
{
    a.x=30; //
}

You're passing a by value, not by reference, so when you pass test to putvalue , you're actually modifying a copy of test , not the original object itself, and your modified copy gets lost when putvalue returns.

You can do it with a pointer:

class X
{
    int x;
public:
    void showdata()
    {
        cout << "x =" << x << endl;
    }

    friend void putvalue(X* a);
};

void putvalue(X* a)
{
    a->x = 30;
}

int main()
{
    X test;
    putvalue(&test);
    test.showdata();
    getch();
    return 0;
}

You can do it with a reference:

class X
{
    int x;
public:
    void showdata()
    {
        cout << "x =" << x << endl;
    }

    friend void putvalue(X& a);
};

void putvalue(X& a)
{
    a.x = 30;
}

int main()
{
    X test;
    putvalue(test);
    test.showdata();
    getch();
    return 0;
}
gusano79 247 Posting Shark
#include <iostream.h>

Try this instead:

#include <iostream>
gusano79 247 Posting Shark

Got it.

That's enormous. I'm familiar with IDA and I have the free version installed already. It looks like it's a standard x86 PE, so it should work... if you post the IDA database, that would make it easier to navigate.

As for finding the code that handles the data files, I'd start by searching for ".dat", and that shows up on line 543257 in the .asm file... then look for references to labels like "aDataCsg1_dat". There don't appear to be any, but that line has its own offset label, which IDA must have put there because something else referenced it... yep, on line 56323. Looks like "sub_42F280" (line 56304) is a procedure that returns data file names, and it's called in a variety of places. Anyway, that's off the top of my head... the IDA DB will help immensely.

So. The data file you bundled with the disassembly isn't 3ds-related at all--it's a standard WAVE file. Just rename it from "css11.dat" to "css11.wav" and play it in whatever media player you like. Are there specific media files you're interested in? That will help focus our investigation.

gusano79 247 Posting Shark

The site is returning XHTML; this is a good thing. It seems to me that the simplest approach is to load the response as an XML document, and then use a few XPath queries to get the data you need. Are you familiar with the System.Xml namespaces at all?

gusano79 247 Posting Shark

Ah, okay, that makes more sense. As far as I know, 3ds Max binary files are proprietary, so it won't be obvious what the chunk IDs are even supposed to be... I suppose that's why you're posting, right? :) Are you looking for insight into the 3ds format, or do you want to see what the disassembled application is actually doing with the files? Or is it something else you're after?

If you're able to post/link something I can examine offline, that would be best--I can only check DW sporadically.

gusano79 247 Posting Shark

Does your application get a response back from the Web site? Please post the response (same as what you're writing to the "dangdang" file) so we can help you figure out how to extract the data you want.

gusano79 247 Posting Shark

A simple Split is fine if all you have to do is split at the underscores and pass the parts off to date/time parsers, but it starts to get messy if you have to do more text manipulation after the split.

This might be slightly overkill for the posted problem, but I suggest you become familiar with regular expressions (if you aren't already) as something to keep in mind for when you have to parse formatted text that isn't dead simple.

gusano79 247 Posting Shark

I've disassembled a program to attempt to understand the application's structure for importing the data files. I have an extensive background is Java and C++ but I can't find any resources explaining importing files and reading them in assembly. What I'm hoping to find is someone who can simply tell me what the headers of the data file are. Any help would be greatly appreciated.

If by "headers" you mean the header files from a C/C++ program, you're not going to find them in a disassembly. A structure/class definition provides the compiler information about the shape of an object, but the compiler doesn't save that information anywhere; it's implicit in how the resulting native executable handles data. There are disassemblers that provide tools to help you manage structure definitions, but you'll generally have to do the work of figuring out what they are on your own--at least, that's my experience.

Do you know what language the original application was written in? What platform it was compiled for? Can you post the disassembly or the original application? I'm assuming you're not breaking any software license agreements by disassembling it; if you are, don't post them.

gusano79 247 Posting Shark

no! man it is still not working. m upset now. :'(

Post your new code, please. Also, what does "not working" mean here? Are you getting the same output as before, or is it going wrong differently after the change?

gusano79 247 Posting Shark

I ran your program with an input of 2, 5, 3, 6, 4 . The heap is 6, 5, 3, 2, 4 , which looks okay, but after it does the 'sort' part of the heap sort, I end up with 5, 5, 5, 5, 6 .

It looks like you're not swapping array members correctly--it's as if one of them is getting copied and the other lost. As a first step, I recommend you write a swap function, something like void swap(int a, int b) { ... } , that exchanges the two values at indexes a and b within your array. Then rewrite the rest of your code to use that function instead of doing it directly.

Doing this will make your code easier to read, and it might expose an obvious problem. If it still doesn't work, we can look at your heap sort implementation in more detail.

gusano79 247 Posting Shark

Like this:

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

int n, a[10];

void display();

void insert(int);

int del();

int main()
{
    int i, item = 0, j;
    n = 1;
    printf("enter the numbers:");
    for(i = 1; i < 6; i++)
        scanf("%d", &a[i]);
    for(j = 1; j < 5; j++)
    {
        insert(a[j+1]);
    }
    display();
    while(n > 1)
    {
        item = del();
        a[n+1] = item;

    }
    display();
    getch();
}

void display()
{
    int i;
    for(i = 1; i < 6; i++)
    {
        printf("%d ", a[i]);
    }

}

void insert(int item1)
{
    int ptr, par;
    n++;
    ptr = n;

    while(ptr > 1)
    {
        par = ptr / 2;
        if(item1 < a[par])
        {
            a[ptr] = item1;

            return;
        }
        a[ptr] = a[par];
        ptr = par;
    }
    a[1] = item1;

}

int del()
{
    int item, left, right, ptr, last;
    item = a[1];
    last = a[n];
    n--;
    ptr = 1;
    left = 2;
    right = 3;
    while(right <= n)
    {
        if(last > a[left] && last > a[right])
        {
            a[ptr] = last;
            return(item);
        }
        if(a[left] > a[right])
        {
            a[ptr] = a[left];
            ptr = left;
        }
        else
        {
            a[ptr] = a[right];
            ptr = right;
        }
        left = ptr * 2;
        right = left + 1;
    }
    if(left == n && last < a[left])
    {
        ptr = left;
        a[ptr] = last;
    }
    return(item);
}
gusano79 247 Posting Shark
gusano79 247 Posting Shark

I am passing to the function a list, such as '(1 2 3), and I need the function to return seperate lists, such as '(1)'(1 2)'(1 2 3).

It's not entirely clear what you want. Are you trying to return all possible sublists, so that (sublists '(1 2 3)) returns ((1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) ?

gusano79 247 Posting Shark

I can get the functions, if they're private, but it returns other functions that I don't even have.

Which methods are showing up? They are probably inherited from other classes. If you use the overload of Type.GetMembers that takes a BindingFlags parameter, you can include BindingFlags.DeclaredOnly to only get members that were declared by that type.

I made a function which got all functions from a console application. Do you know how to do this with a Forms application?

Hey, I found out how to do that. Do you know how I can get all variables within the namespace, class, function, etc?

Namespaces don't directly contain storage, so there's nothing I can think of that you could call a "variable" to get from there.

You can use Type.GetFields to get variables that are declared as members of a class or structure.

For methods... this may not be exactly what you're looking for, but you could use the MethodInfo.GetMethodBody method and the MethodBody.LocalVariables property to get variables that are local to a method.

gusano79 247 Posting Shark

Inside drawCube , comment out this line and see what happens:

glTranslatef(225.0f, 225.0f, 0.0f);

Some other things you might consider:

  • GLUT already includes gl.h and glu.h , so you don't need to include them yourself.
  • In display , why are you calling glEnd ? There's no matching glBegin .
  • Why does read_file have a parameter? You're not using it.
  • You created your GLUT window with the GLUT_SINGLE option, which makes it single-buffered. There's never a need to call glutSwapBuffers .
gusano79 247 Posting Shark

Your compiler should have an "output to assembly" option; for GCC, this is "-S"

gusano79 247 Posting Shark

Use code tags, please!

using (SqlDataReader reader = cmd.ExecuteReader())
if (reader.Read())
SearchingDate = (DateTime)reader[0];

If that third line is setting SearchingDateto the current date and time, then that must be the value in the first row and column of your data. The actual current date and time only comes from DateTime.Now (see here)... could you also post the SQL command you're running and a short set of example data that gets you this result?

gusano79 247 Posting Shark

The problem is in this line:

GLint numstrip, numlines, x, y;

You're declaring x and y as integer variables, but the values in your text file are decimals. Try declaring your variables like this:

GLint numstrip, numlines;
GLfloat x, y;

That got it to draw something for me.

Also: You're loading the contents of house1.txt inside your draw function. I can see how this makes the program simpler to write, but realize that it will open and read the file every single time the GLUT window needs to redraw itself--put some output to cout inside of draw if you're not sure what I mean there. It is much better practice to attempt to read the file only once, before you even initialize GLUT, and store its contents into a variable somewhere that draw can reference later.

gusano79 247 Posting Shark
gusano79 247 Posting Shark

The second parameter to the Timer constructor you're using needs to implement ActionListener . JFrame doesn't implement it, so you'll have to do that in your Morning class yourself.

Also: You'll get better results posting questions like this in the Java forum.