Yeah I hope to get a little more knowledgeable on what he does for his windows and such, but right now the project is due in about 27 hours so I am trying to just deal with what I can at the moment.
Once you have the window up and running, you ought to not have to touch the code until you need to do something like changing the screen resolution or back buffer format or something. Usually school projects won't require you to do this, but it is nice if you support it. Good luck in your OpenGL escapades! I haven't worked with it for a bit, I tend to prefer DirectX for my graphics API.
Also there are 1001 easier ways to make a compiling OpenGL win32 application than actually using the win32 api because seriously fuck that shit. NeHe's tutorials are an exercise in masochism, and if you try to follow them you'll usually wind up with a non-working program because he leaves stuff out of the step by step.
Also there are 1001 easier ways to make a compiling OpenGL win32 application than actually using the win32 api because seriously fuck that shit. NeHe's tutorials are an exercise in masochism, and if you try to follow them you'll usually wind up with a non-working program because he leaves stuff out of the step by step.
True story. Libraries are your best friend, I'd only use the Win32 API if you have to make a couple of calls and nothing more.
Yeah I'm about 90% done with the project. I'm able to read in a PLY file, and display that image on the screen, but I have to show the top, side, and front view. For shits and grins I started reading through his window commands.
Seriously? I would 100% rather have less functionality than to run through that code again.
How is DirectX compared to OpenGL in terms of programming? Is it all Matrix based as well?
I dunno, I've used it all of one time when I thought I was going to have to make a learn-Chinese practice app, and was pretty turned off by the fact that all the good tools cost a lot of money and also the language was just different enough from others that I knew that I was having to look up the syntax for everything.
I cannot wait to see what kind of nightmare that turns out to be. To me this sounds like instead of trying to improve Flash's performance and work from there they've just gone the "fuck it, we'll just turn each FLA into its own resource-hogging crash-inducing app" route.
But that's probably not fair of me, and Adobe's probably spent a lot of time and resources on this so I'll just sit back and see how this plays out.
iTunesIsEvil on
0
HalibutPassion FishSwimming in obscurity.Registered Userregular
Yeah I'm about 90% done with the project. I'm able to read in a PLY file, and display that image on the screen, but I have to show the top, side, and front view. For shits and grins I started reading through his window commands.
Seriously? I would 100% rather have less functionality than to run through that code again.
How is DirectX compared to OpenGL in terms of programming? Is it all Matrix based as well?
NeHe's site has been dead for a while now, ever since its creator (I think his name was Jeff) left due to personal reasons. While he was writing his tutorials, he always tried to be up front about how he might not have the most elegant code. Since then, Visual Studio (and Windows for that matter) has changed a lot, and I'm sure a lot of the setup stuff isn't the best way to do it. But at the time he wrote the articles, the base code worked pretty well.
I believe a group of people have been trying to maintain the site, but I didn't stick around for long enough to see if they got it rolling like it used to.
I've only played around with DirectX once, but I can tell you without a doubt that it is matrix based. You'd be hard-pressed to find a graphics library that uses something other than matrix math for transformations (or at least something that excludes matrices entirely).
I should probably point out that my c/c++/windows knowledge is a little rusty, so all of this is from memory. As of about a year a go I started writing all of my 3D stuff in Scala/JOGL and haven't looked back since.
I cannot wait to see what kind of nightmare that turns out to be. To me this sounds like instead of trying to improve Flash's performance and work from there they've just gone the "fuck it, we'll just turn each FLA into its own resource-hogging crash-inducing app" route.
But that's probably not fair of me, and Adobe's probably spent a lot of time and resources on this so I'll just sit back and see how this plays out.
No, what it is is that Apple won't let them put Flash in the web browser for some stupid goddamn reason so Adobe figures they need to get on there somehow.
Expect apps made with this to be rejected for seemingly random reasons. But then, that's the App Store for ya.
Yeah I'm about 90% done with the project. I'm able to read in a PLY file, and display that image on the screen, but I have to show the top, side, and front view. For shits and grins I started reading through his window commands.
Seriously? I would 100% rather have less functionality than to run through that code again.
How is DirectX compared to OpenGL in terms of programming? Is it all Matrix based as well?
Anything connected with 3D is going to involve phenomenal amounts of linear algebra
I have a series of commands that are in a txt file, that each run a different method. Not the problem.
If the command is not one available, it will catch the InputMismatchException. Sort of not a problem.
My problem then is when it does catch this error I need for it to print out what command caused it. I also need for the program to differentiate between an InputMismatchException and a command error
InputMismatchError needs to catch input errors, example: "Hello mom".
I need another exception or way to catch command errors like: LDC with no/non-int following.
/*------------------------------------------------
*
*
*
-----------------------------------------------*/
import java.util.*;
import java.io.*;
public class Proj40224
{
private Stack<Integer> stack;
public Proj40224()
{
stack = new Stack<Integer>();
}
public void clr()
{
while(!stack.empty())
{
stack.pop(); //while the stack is not empty, pop every element
}
}
public void hlt()
{
System.out.print("[machine halted]");
}
public void neg()
{
try
{
stack.push(-1*stack.pop()); //takes the top item of stack, removes it, *-1, and then re-adds it to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void add()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x+y); //takes the top two items of stack, removes them, sums them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void sub()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x-y); //takes the top two items of stack, removes them, subtracts them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void mul()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x*y); //takes the top two items of stack, removes them, multiplies them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void div()
{
try
{
int x = stack.pop();
int y = stack.pop();
if(x==0)
throw new ArithmeticException(); //throws ArithmeticException caught by runProj that prints out [error - division by zero] and halts the program
stack.push(y/x); //takes the top two items of stack, removes them, divides them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void ldc(int n)
{
stack.push(n); //puts value to top of stack
}
public void inp(int n)
{
stack.push(n);
}
public int out()
{
int answer = 0;
try
{
answer = stack.peek();
stack.pop();
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
return answer;
}
public String nln()
{
return "\n";
}
public void dbg()
{//Found using the java api. Stack inherits methods elementAt() and size() from Vector
try
{
System.out.print("DEBUG:[");
for(int i = 0; i < stack.size()-1; i++) //for size-1 of Stack, starting at 0(bottom of stack), print stack.elementAt(i) until reach end
{
System.out.print(stack.elementAt(i)+", ");
}
System.out.println(stack.lastElement()+"](top)"); //print top of stack element
}
catch(EmptyStackException e)
{
System.err.println("](top)");//DEBUG:[](top)
}
catch(NoSuchElementException e)
{
System.err.println("](top)");
}
}
public static void main(String[] args)
{
Scanner scanUser = new Scanner(System.in);
System.out.println("Expression Stack Machine - E. Albrecht");
if(args.length == 1)
{
runProj(args[0]);
}
else
{
System.out.println("No file entered, please enter one now");
String input = scanUser.next();
runProj(input);
}
}//end main
public static void runProj(String input)
{
Scanner scanFile;
Proj40224 stack = new Proj40224();
System.out.println("File: "+input);
try
{
scanFile = new Scanner(new File(input));
Scanner scan = new Scanner(System.in);
System.out.println("");
String command = "";
while(!command.equalsIgnoreCase("hlt"))
{
command = scanFile.next();
try
{
if(command.equalsIgnoreCase("clr"))
stack.clr();
if(command.equalsIgnoreCase("hlt"))
{
stack.hlt();
break;
}
else if(command.equalsIgnoreCase("neg"))
stack.neg();
else if(command.equalsIgnoreCase("add"))
stack.add();
else if(command.equalsIgnoreCase("sub"))
stack.sub();
else if(command.equalsIgnoreCase("mul"))
stack.mul();
else if(command.equalsIgnoreCase("div"))
stack.div();
else if(command.equalsIgnoreCase("ldc"))
stack.ldc(scanFile.nextInt());
else if(command.equalsIgnoreCase("inp"))
{
System.out.print("input: ");
int n = scan.nextInt();
stack.inp(n);
}
else if(command.equalsIgnoreCase("out"))
System.out.println("output: "+stack.out());
else if(command.equalsIgnoreCase("nln"))
stack.nln();
else if(command.equalsIgnoreCase("dbg"))
stack.dbg();
if(!scanFile.hasNext())
{
System.out.print("[warning - no HLT instruction]");
break;
}
}//end try
catch(InputMismatchException e)
{
System.out.println("[warning - illegal command '"+e.getCause()+"' ignored]");
//e.printStackTrace();
}
catch(ArithmeticException e)
{
System.out.print("[error - division by zero]");
break;
}
catch(NumberFormatException e)
{
System.out.println("[warning - illegal input ignored]");
}
}//end while
}
catch(IOException e)
{
System.err.print(e);
}
}
}//end class
Right now the InputMismatchException is doing both, so it's setup to print the message. But I can't get it to print what is causing the error.
Since this is a school project, I'm not asking for the quick dirty answer. But if someone could point out what's going wrong with my setup I'll try working from there.
I have a series of commands that are in a txt file, that each run a different method. Not the problem.
If the command is not one available, it will catch the InputMismatchException. Sort of not a problem.
My problem then is when it does catch this error I need for it to print out what command caused it. I also need for the program to differentiate between an InputMismatchException and a command error
InputMismatchError needs to catch input errors, example: "Hello mom".
I need another exception or way to catch command errors like: LDC with no/non-int following.
/*------------------------------------------------
*
*
*
-----------------------------------------------*/
import java.util.*;
import java.io.*;
public class Proj40224
{
private Stack<Integer> stack;
public Proj40224()
{
stack = new Stack<Integer>();
}
public void clr()
{
while(!stack.empty())
{
stack.pop(); //while the stack is not empty, pop every element
}
}
public void hlt()
{
System.out.print("[machine halted]");
}
public void neg()
{
try
{
stack.push(-1*stack.pop()); //takes the top item of stack, removes it, *-1, and then re-adds it to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void add()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x+y); //takes the top two items of stack, removes them, sums them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void sub()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x-y); //takes the top two items of stack, removes them, subtracts them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void mul()
{
try
{
int x = stack.pop();
int y = stack.pop();
stack.push(x*y); //takes the top two items of stack, removes them, multiplies them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void div()
{
try
{
int x = stack.pop();
int y = stack.pop();
if(x==0)
throw new ArithmeticException(); //throws ArithmeticException caught by runProj that prints out [error - division by zero] and halts the program
stack.push(y/x); //takes the top two items of stack, removes them, divides them, then re-adds to top of stack
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
}
public void ldc(int n)
{
stack.push(n); //puts value to top of stack
}
public void inp(int n)
{
stack.push(n);
}
public int out()
{
int answer = 0;
try
{
answer = stack.peek();
stack.pop();
}
catch(EmptyStackException e)
{
System.out.print("[error - empty stack]");
}
return answer;
}
public String nln()
{
return "\n";
}
public void dbg()
{//Found using the java api. Stack inherits methods elementAt() and size() from Vector
try
{
System.out.print("DEBUG:[");
for(int i = 0; i < stack.size()-1; i++) //for size-1 of Stack, starting at 0(bottom of stack), print stack.elementAt(i) until reach end
{
System.out.print(stack.elementAt(i)+", ");
}
System.out.println(stack.lastElement()+"](top)"); //print top of stack element
}
catch(EmptyStackException e)
{
System.err.println("](top)");//DEBUG:[](top)
}
catch(NoSuchElementException e)
{
System.err.println("](top)");
}
}
public static void main(String[] args)
{
Scanner scanUser = new Scanner(System.in);
System.out.println("Expression Stack Machine - E. Albrecht");
if(args.length == 1)
{
runProj(args[0]);
}
else
{
System.out.println("No file entered, please enter one now");
String input = scanUser.next();
runProj(input);
}
}//end main
public static void runProj(String input)
{
Scanner scanFile;
Proj40224 stack = new Proj40224();
System.out.println("File: "+input);
try
{
scanFile = new Scanner(new File(input));
Scanner scan = new Scanner(System.in);
System.out.println("");
String command = "";
while(!command.equalsIgnoreCase("hlt"))
{
command = scanFile.next();
try
{
if(command.equalsIgnoreCase("clr"))
stack.clr();
if(command.equalsIgnoreCase("hlt"))
{
stack.hlt();
break;
}
else if(command.equalsIgnoreCase("neg"))
stack.neg();
else if(command.equalsIgnoreCase("add"))
stack.add();
else if(command.equalsIgnoreCase("sub"))
stack.sub();
else if(command.equalsIgnoreCase("mul"))
stack.mul();
else if(command.equalsIgnoreCase("div"))
stack.div();
else if(command.equalsIgnoreCase("ldc"))
stack.ldc(scanFile.nextInt());
else if(command.equalsIgnoreCase("inp"))
{
System.out.print("input: ");
int n = scan.nextInt();
stack.inp(n);
}
else if(command.equalsIgnoreCase("out"))
System.out.println("output: "+stack.out());
else if(command.equalsIgnoreCase("nln"))
stack.nln();
else if(command.equalsIgnoreCase("dbg"))
stack.dbg();
if(!scanFile.hasNext())
{
System.out.print("[warning - no HLT instruction]");
break;
}
}//end try
catch(InputMismatchException e)
{
System.out.println("[warning - illegal command '"+e.getCause()+"' ignored]");
//e.printStackTrace();
}
catch(ArithmeticException e)
{
System.out.print("[error - division by zero]");
break;
}
catch(NumberFormatException e)
{
System.out.println("[warning - illegal input ignored]");
}
}//end while
}
catch(IOException e)
{
System.err.print(e);
}
}
}//end class
Right now the InputMismatchException is doing both, so it's setup to print the message. But I can't get it to print what is causing the error.
Since this is a school project, I'm not asking for the quick dirty answer. But if someone could point out what's going wrong with my setup I'll try working from there.
Help is greatly appreciated.
What does InputMismatchException currently print? Also, try e.getMessage() instead of getCause().
Also, you do know that
1) You can throw your own Exceptions via the throw() keyword?
2) Exceptions and Errors are different?
Yeahh maybe I should have payed attention in my linear algebra class. :P
From what I found poking around at 3D stuff, matrix math is the most complicated thing, and everything seems to have a variety of functions written for it already.
What does InputMismatchException currently print? Also, try e.getMessage() instead of getCause().
Also, you do know that
1) You can throw your own Exceptions via the throw() keyword?
2) Exceptions and Errors are different?
InputMismatchException currently prints:
[warning - illegal command 'null' ignored]
with getCause()
[warning - illegal command 'null' ignored]
which according to the API means that it cannot determine the cause of the exception.
1) yes and I have tried it. What happens is [warning - illegal command 'java.lang.InputMismatchException' ignored]. With get cause I at least get 1 of them semi-correct (see below).
2) I do know the difference between an error and an exception. These "errors" are misleading. For the purposes of the program, certain exceptions cause "hard errors" and cause the program to end, others are caught and ignored letting computations resume.
I get 'null' AND another line with the command(ex: 2.99) as listed in my post above.
So I need to do both right? But I need to re-look at the code and determine where InputMismatchException is being caught and why it's being caught? Or should I rework that method to catch the InputMismatchException, and throw it so the catch block catches why?
#include <windows.h>
#include <windowsx.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "Whoooo";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
void Template_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
// code to handle WM_MOUSEMOVE...
}
void Template_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x,
int y, UINT keyFlags)
{
// code to handle WM_LBUTTONDOWN...
}
void Template_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)
{
// code to handle WM_LBUTTONUP
}
HBRUSH Template_OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild,
int type)
{
// code to handle WM_CTLCOLOR
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT _export CALLBACK WindowProcedure(HWND hwnd, WORD msg,
WPARAM wParam,
LPARAM lParam)
{
switch (msg)
{
HANDLE_MSG(hwnd, WM_MOUSEMOVE, Template_OnMouseMove);
HANDLE_MSG(hwnd, WM_LBUTTONDOWN, Template_OnLButtonDown);
HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK, Template_OnLButtonDown);
HANDLE_MSG(hwnd, WM_LBUTTONUP, Template_OnLButtonUp);
default:
return WindowProcedure(hwnd, msg, wParam, lParam);
}
}
I get this error:
|22|undefined reference to `_Z15WindowProcedureP6HW[email protected]|
On this line:
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
I'm working from an example on one of Microsoft's many websites and am not 100% sure of what I'm doing, but as far as I can tell WindowProcedure is referenced correctly in all parts where it's used.
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
I'm working from an example on one of Microsoft's many websites and am not 100% sure of what I'm doing, but as far as I can tell WindowProcedure is referenced correctly in all parts where it's used.
Two things.
1.) It looks like it's a linker error, and you're using C++, which means you've most likely accidentally performed function overloading. I can't remember if WORD and UINT evaluate to the same basic type, but I don't think they do. What I think you've done is declared one WindowProcedure function with arguments:
WindowProcedure (HWND, UINT, WPARAM, LPARAM);
This one you used to register your class.
But then you've *defined* another WindowProcedure function with arguments:
WindowProcedure(HWND, WORD, WPARAM, LPARAM);
In C++, you've now got two functions with the same name, but different arguments due to function overloading. Solution: Change WORD to UINT.
2.) The window procedure shouldn't be infinitely recursive!
So. Weird problem. I am working on another project using C/C++. I am just currently trying to output whatever the user types to the screen, but it stops at the spaces. The weird thing is that I'm not doing anything different from what the instructor did and I can't figure out what I am doing wrong. I'll post the small functions I am trying to do.
ourgets() is the function he wrote. His printf after the function call shows all the spaces.
redirect() is my function.
If I type "ls > test" the output I get is "The command you typed in is ls" and that's it.
int main()
{
char buf[1024]; // better not type longer than 1023 chars
char aft[1024]; // this is to keep track of what is typed after a command
usage();
for (;;) {
*buf = 0; // clear old input
printf("%s", "sh33% "); // prompt
ourgets(buf);
printf("cmd [%s]\n", buf); // just print out what we got as-is
setArgsGiven(buf, arg, types, nArgsMax);
[B] for(int i=0; i<1024; i++)
{
if(buf[i] == '>')
{
redirect(buf);
}
}[/B]
int k = findCmd(buf, types);
if (k >= 0)
invokeCmd(k, arg);
else
usage();
}
}
void ourgets(char *buf)
{
fgets(buf, 1024, stdin);
char * p = index(buf, '\n');
if (p) *p = 0;
}
void redirect(char *buf)
{
printf("The command you typed in is: %s \n",buf);
}
Yeahh maybe I should have payed attention in my linear algebra class. :P
From what I found poking around at 3D stuff, matrix math is the most complicated thing, and everything seems to have a variety of functions written for it already.
Working with the math is somewhat complicated (all Graphics APIs eventually require conversion to a matrix for vertex transforms) but I would say it is folly to let a math library handle your transforms without understanding what they mean. There is much, much more math besides linear algebra involved in working with a 3D graphics engine, depending on how deep you want to go.
If you are serious about learning some of the fundamentals of how modern graphics techniques are implemented, I would suggest trying to get a copy of this book. I found it to be a great reference for the underlying concepts of how modern graphics engines are created, and a good stepping stone toward more complex techniques.
After the math, the most complicated thing(or at least what I spend the most time doing) is figuring out how best to organize data so that you send the least amount of data to the GPU and minimize sync times between the CPU and GPU. This is actually why I prefer DirectX to OpenGL, in my experience DirectX gives a much better interface to the more advanced features of modern graphics hardware. Also HLSL is a massively better shading language than GLSL.
Also, I really quickly compiled that code, removing all the functions that weren't defined, I got the expected result.
cmd [ls > test]
The command you typed in is: ls > test
The only difference is that I had to find the newline myself rather than use his index operator. Just a nitpicky note, but you seem to have a bit of an indenting/curly brace problem starting with the closing curly brace of the inner for loop. I thought for a moment that your command finding operations were taking place inside that inner for loop for a moment.
So is there a reference anywhere for the "Dialog Based Window" thing Code::Blocks produces? I've been looking all over and haven't been able to find anything. All I wanted to do was open one dialog from another.
I'm still learning/brushing up on C#. It seems like anonymous delegates and lambda expressions are pretty much the same thing. Am I missing something? Are there any times where one would be more beneficial than the other?
Nightslyr on
PSN/XBL/Nintendo/Origin/Steam: Nightslyr 3DS: 1607-1682-2948 Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
I'm still learning/brushing up on C#. It seems like anonymous delegates and lambda expressions are pretty much the same thing. Am I missing something? Are there any times where one would be more beneficial than the other?
Lambas are essentially sugar; the compiler can decompose them into anonymous delegates, so in that sense the benefit is merely that they are a cleaner and more concise way of writing equivalent functionality.
But the compiler can also decompose them into expression trees, so in that sense they are more versatile than anonymous delegates.
Why does buf change???? The first printf for buf gives me whatever I typed in. The second one gives me gibberish. I really should just become an IT guy because this software development stuff isn't working out for me.
Why does buf change???? The first printf for buf gives me whatever I typed in. The second one gives me gibberish. I really should just become an IT guy because this software development stuff isn't working out for me.
When you run into a problem like this, it's good to whip up an outline where you describe what you want to happen at each step in English.
edit:
Here's an example using an assignment I did for scripting class:
The goal is to shift our array of numbers left one with each iteration, and print it out until all 10 rows are filled.
The content of these isn't important at this point; they're just initialized because it's good programming practice.
column 1 temp = "0"
colunm 2 temp = "0"
column 3 temp = "0"
column 4 temp = "0"
column 5 temp = "0"
column 6 temp = "0"
column 7 temp = "0"
column 8 temp = "0"
column 9 temp = "0"
column 10 temp = "0"
Begin a loop with 10 iterations.
Print the contents of the column 1-10 variables.
Copy the contents of column 2-10 to column 1-9 temp, then copy column 1 to column 10 temp. This will shift the array of numbers one place left.
Copy colum 1-10 temp to column 1-10.
Repeat loop until all 10 rows are filled.
End the loop
#!/bin/bash
#Wherein we print a series of numbers
#These variables are where the final result of each iteration is stored
column_1="1"
column_2="2"
column_3="3"
column_4="4"
column_5="5"
column_6="6"
column_7="7"
column_8="8"
column_9="9"
column_10="10"
#These are temporary variables used in the number shifting process.
temp_column_1="0"
temp_column_2="0"
temp_column_3="0"
temp_column_4="0"
temp_column_5="0"
temp_column_6="0"
temp_column_7="0"
temp_column_8="0"
temp_column_9="0"
temp_column_10="0"
for i in 1 2 3 4 5 6 7 8 9 10
do
#Print the number array
echo "$column_1 $column_2 $column_3 $column_4 $column_5 $column_6 $column_7 $column_8 $column_9 $column_10"
#Shift the array
temp_column_1="$column_2"
temp_column_2="$column_3"
temp_column_3="$column_4"
temp_column_4="$column_5"
temp_column_5="$column_6"
temp_column_6="$column_7"
temp_column_7="$column_8"
temp_column_8="$column_9"
temp_column_9="$column_10"
temp_column_10="$column_1"
#Copy the shifted array out of the temporary variables in to the main variables
column_1="$temp_column_1"
column_2="$temp_column_2"
column_3="$temp_column_3"
column_4="$temp_column_4"
column_5="$temp_column_5"
column_6="$temp_column_6"
column_7="$temp_column_7"
column_8="$temp_column_8"
column_9="$temp_column_9"
column_10="$temp_column_10"
done
int main()
{
char buf[1024]={0}; // better not type longer than 1023 chars, set all to 0.
char aft[1024]={0}; // this is to keep track of what is typed after a command
int j=0;
usage();
for (;;) {
printf("%s", "sh33% "); // prompt
ourgets(buf);
printf("cmd [%s]\n", buf); // just print out what we got as-is
if (buf[0] == 0)
continue;
if (buf[0] == '#')
continue; // this is a comment line, do nothing
if (buf[0] == '!') // begins with !, execute it as
system(buf + 1); // a normal shell cmd
else
{
setArgsGiven(buf, arg, types, nArgsMax);
for(int i=0; i<1024; i++)
{
if(buf[i] == '>')
{
printf("i = %d \n",i);
printf("%s\n",buf);
i+=2;
while(buf[i] != ' ')
{
aft[j] = buf[i];
i++;
j++;
}
printf("First part: %s Second part: %s \n",buf,aft);
redirect(buf);
}
}
int k = findCmd(buf, types);
if (k >= 0)
invokeCmd(k, arg);
else
usage();
}
}
}
This is for my Operating Systems class. We're supposed to be making our own small OS. I am trying to get the '>' (redirect) working. But BEFORE I do that I need to get the commands split up. If someone types "ls > test.txt" I want to take the output of ls from our virtual disk and put it into the file test.txt on the real hard drive. The problem is that I don't know how to split it up. I need to be able to say "Hey, they typed in '>' which means there are two arguments, split them up and do the job".
Using descriptive variable names would make that a whole lot easier to read.
Wish I could... The professor wrote everything and this is just a small part of a larger program. The entire thing looks terrible but I am trying to work with what I've got.
buf = buffer, what the user types in (he wrote)
aft = after, after the '>' (I wrote)
ourgets() = gets the input from the user
sh33% = no idea why he uses this, but it's the output for the user to type something in
arg, types, nMax = no idea what they are
what is it supposed to do? I get the expected result which is the same, but replacing "test" with "test2"
Oops sorry. I'm being completely vague when I respond and I shouldn't. This is what happens on my machine:
sh33% ls > test
cmd [ls > test]
i = 3
ls
First part: ls Second part: test
The command you typed in is: ls
sh33% ls > test2
cmd [ls > test2]
i = 3
ls
First part: ls Second part:
The command you typed in is: ls
I'm still learning/brushing up on C#. It seems like anonymous delegates and lambda expressions are pretty much the same thing. Am I missing something? Are there any times where one would be more beneficial than the other?
Lambas are essentially sugar; the compiler can decompose them into anonymous delegates, so in that sense the benefit is merely that they are a cleaner and more concise way of writing equivalent functionality.
But the compiler can also decompose them into expression trees, so in that sense they are more versatile than anonymous delegates.
Awesome! Thanks
Nightslyr on
PSN/XBL/Nintendo/Origin/Steam: Nightslyr 3DS: 1607-1682-2948 Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
Finally getting somewhere thanks to you guys. I appreciate it. I do have a question and google has failed me.
I'm using dup2 (if anyone knows what that is...) to redirect the output from one file to another file. The problem is, after I use dup2 it basically shuts off the entire output of the program from then on. Does anyone know how to get the dup2 back? I'll post my redirect function:
void redirect(char *bef, char *aft)
{
int fd;
int k = findCmd(bef,types);
if(k >= 0)
{
fd = open(aft, O_CREAT | O_WRONLY);
close(1);
dup(fd);
invokeCmd(k,arg);
}
}
bef is the string before the '>' and aft is the string after the '>'; findCmd returns -1 if it can't find the command put in by the bef.
Posts
Seriously? I would 100% rather have less functionality than to run through that code again.
How is DirectX compared to OpenGL in terms of programming? Is it all Matrix based as well?
http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/
Very good, because I am quickly getting tired of Objective-C.
I dunno, I've used it all of one time when I thought I was going to have to make a learn-Chinese practice app, and was pretty turned off by the fact that all the good tools cost a lot of money and also the language was just different enough from others that I knew that I was having to look up the syntax for everything.
But that's probably not fair of me, and Adobe's probably spent a lot of time and resources on this so I'll just sit back and see how this plays out.
NeHe's site has been dead for a while now, ever since its creator (I think his name was Jeff) left due to personal reasons. While he was writing his tutorials, he always tried to be up front about how he might not have the most elegant code. Since then, Visual Studio (and Windows for that matter) has changed a lot, and I'm sure a lot of the setup stuff isn't the best way to do it. But at the time he wrote the articles, the base code worked pretty well.
I believe a group of people have been trying to maintain the site, but I didn't stick around for long enough to see if they got it rolling like it used to.
I've only played around with DirectX once, but I can tell you without a doubt that it is matrix based. You'd be hard-pressed to find a graphics library that uses something other than matrix math for transformations (or at least something that excludes matrices entirely).
I should probably point out that my c/c++/windows knowledge is a little rusty, so all of this is from memory. As of about a year a go I started writing all of my 3D stuff in Scala/JOGL and haven't looked back since.
No, what it is is that Apple won't let them put Flash in the web browser for some stupid goddamn reason so Adobe figures they need to get on there somehow.
Expect apps made with this to be rejected for seemingly random reasons. But then, that's the App Store for ya.
Anything connected with 3D is going to involve phenomenal amounts of linear algebra
I have a series of commands that are in a txt file, that each run a different method. Not the problem.
If the command is not one available, it will catch the InputMismatchException. Sort of not a problem.
My problem then is when it does catch this error I need for it to print out what command caused it. I also need for the program to differentiate between an InputMismatchException and a command error
InputMismatchError needs to catch input errors, example: "Hello mom".
I need another exception or way to catch command errors like: LDC with no/non-int following.
Example:
inputs:
LDC
LDC 2.99
Hello Mom
Output should look like:
[warning illegal command 'LDC' ignored]
[warning illegal command '2.99' ignored]
[warning illegal input ignored] <- the difference
/*------------------------------------------------ * * * -----------------------------------------------*/ import java.util.*; import java.io.*; public class Proj40224 { private Stack<Integer> stack; public Proj40224() { stack = new Stack<Integer>(); } public void clr() { while(!stack.empty()) { stack.pop(); //while the stack is not empty, pop every element } } public void hlt() { System.out.print("[machine halted]"); } public void neg() { try { stack.push(-1*stack.pop()); //takes the top item of stack, removes it, *-1, and then re-adds it to top of stack } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } } public void add() { try { int x = stack.pop(); int y = stack.pop(); stack.push(x+y); //takes the top two items of stack, removes them, sums them, then re-adds to top of stack } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } } public void sub() { try { int x = stack.pop(); int y = stack.pop(); stack.push(x-y); //takes the top two items of stack, removes them, subtracts them, then re-adds to top of stack } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } } public void mul() { try { int x = stack.pop(); int y = stack.pop(); stack.push(x*y); //takes the top two items of stack, removes them, multiplies them, then re-adds to top of stack } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } } public void div() { try { int x = stack.pop(); int y = stack.pop(); if(x==0) throw new ArithmeticException(); //throws ArithmeticException caught by runProj that prints out [error - division by zero] and halts the program stack.push(y/x); //takes the top two items of stack, removes them, divides them, then re-adds to top of stack } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } } public void ldc(int n) { stack.push(n); //puts value to top of stack } public void inp(int n) { stack.push(n); } public int out() { int answer = 0; try { answer = stack.peek(); stack.pop(); } catch(EmptyStackException e) { System.out.print("[error - empty stack]"); } return answer; } public String nln() { return "\n"; } public void dbg() {//Found using the java api. Stack inherits methods elementAt() and size() from Vector try { System.out.print("DEBUG:["); for(int i = 0; i < stack.size()-1; i++) //for size-1 of Stack, starting at 0(bottom of stack), print stack.elementAt(i) until reach end { System.out.print(stack.elementAt(i)+", "); } System.out.println(stack.lastElement()+"](top)"); //print top of stack element } catch(EmptyStackException e) { System.err.println("](top)");//DEBUG:[](top) } catch(NoSuchElementException e) { System.err.println("](top)"); } } public static void main(String[] args) { Scanner scanUser = new Scanner(System.in); System.out.println("Expression Stack Machine - E. Albrecht"); if(args.length == 1) { runProj(args[0]); } else { System.out.println("No file entered, please enter one now"); String input = scanUser.next(); runProj(input); } }//end main public static void runProj(String input) { Scanner scanFile; Proj40224 stack = new Proj40224(); System.out.println("File: "+input); try { scanFile = new Scanner(new File(input)); Scanner scan = new Scanner(System.in); System.out.println(""); String command = ""; while(!command.equalsIgnoreCase("hlt")) { command = scanFile.next(); try { if(command.equalsIgnoreCase("clr")) stack.clr(); if(command.equalsIgnoreCase("hlt")) { stack.hlt(); break; } else if(command.equalsIgnoreCase("neg")) stack.neg(); else if(command.equalsIgnoreCase("add")) stack.add(); else if(command.equalsIgnoreCase("sub")) stack.sub(); else if(command.equalsIgnoreCase("mul")) stack.mul(); else if(command.equalsIgnoreCase("div")) stack.div(); else if(command.equalsIgnoreCase("ldc")) stack.ldc(scanFile.nextInt()); else if(command.equalsIgnoreCase("inp")) { System.out.print("input: "); int n = scan.nextInt(); stack.inp(n); } else if(command.equalsIgnoreCase("out")) System.out.println("output: "+stack.out()); else if(command.equalsIgnoreCase("nln")) stack.nln(); else if(command.equalsIgnoreCase("dbg")) stack.dbg(); if(!scanFile.hasNext()) { System.out.print("[warning - no HLT instruction]"); break; } }//end try catch(InputMismatchException e) { System.out.println("[warning - illegal command '"+e.getCause()+"' ignored]"); //e.printStackTrace(); } catch(ArithmeticException e) { System.out.print("[error - division by zero]"); break; } catch(NumberFormatException e) { System.out.println("[warning - illegal input ignored]"); } }//end while } catch(IOException e) { System.err.print(e); } } }//end classRight now the InputMismatchException is doing both, so it's setup to print the message. But I can't get it to print what is causing the error.
Since this is a school project, I'm not asking for the quick dirty answer. But if someone could point out what's going wrong with my setup I'll try working from there.
Help is greatly appreciated.
What does InputMismatchException currently print? Also, try e.getMessage() instead of getCause().
Also, you do know that
1) You can throw your own Exceptions via the throw() keyword?
2) Exceptions and Errors are different?
SE++ Forum Battle Archive
From what I found poking around at 3D stuff, matrix math is the most complicated thing, and everything seems to have a variety of functions written for it already.
InputMismatchException currently prints:
[warning - illegal command 'null' ignored]
with getCause()
[warning - illegal command 'null' ignored]
which according to the API means that it cannot determine the cause of the exception.
1) yes and I have tried it. What happens is [warning - illegal command 'java.lang.InputMismatchException' ignored]. With get cause I at least get 1 of them semi-correct (see below).
adding to the end of the try clause in runProj
else throw new InputMismatchException(command);which should be caught by the catch statement.
Using:
LDC
LDC 2.99
ex:
[warning - illegal command 'null' ignored]
[warning - illegal command 'null' ignored]
[warning - illegal command '2.99' ignored]
2) I do know the difference between an error and an exception. These "errors" are misleading. For the purposes of the program, certain exceptions cause "hard errors" and cause the program to end, others are caught and ignored letting computations resume.
So thinking more about the exceptions.
When I do:
catch(InputMismatchException e) { System.out.println("[warning illegal command'"+e.getCause()+"' ignored]"); }I get 'null'.If I do:
else throw new InputMismatchException(command);I get 'null' AND another line with the command(ex: 2.99) as listed in my post above.So I need to do both right? But I need to re-look at the code and determine where InputMismatchException is being caught and why it's being caught? Or should I rework that method to catch the InputMismatchException, and throw it so the catch block catches why?
#include <windows.h> #include <windowsx.h> /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "Whoooo"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Code::Blocks Template Windows App", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow (hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } void Template_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags) { // code to handle WM_MOUSEMOVE... } void Template_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) { // code to handle WM_LBUTTONDOWN... } void Template_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags) { // code to handle WM_LBUTTONUP } HBRUSH Template_OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type) { // code to handle WM_CTLCOLOR } /* This function is called by the Windows function DispatchMessage() */ LRESULT _export CALLBACK WindowProcedure(HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam) { switch (msg) { HANDLE_MSG(hwnd, WM_MOUSEMOVE, Template_OnMouseMove); HANDLE_MSG(hwnd, WM_LBUTTONDOWN, Template_OnLButtonDown); HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK, Template_OnLButtonDown); HANDLE_MSG(hwnd, WM_LBUTTONUP, Template_OnLButtonUp); default: return WindowProcedure(hwnd, msg, wParam, lParam); } }I get this error:
On this line:
I'm working from an example on one of Microsoft's many websites and am not 100% sure of what I'm doing, but as far as I can tell WindowProcedure is referenced correctly in all parts where it's used.
Two things.
1.) It looks like it's a linker error, and you're using C++, which means you've most likely accidentally performed function overloading. I can't remember if WORD and UINT evaluate to the same basic type, but I don't think they do. What I think you've done is declared one WindowProcedure function with arguments:
WindowProcedure (HWND, UINT, WPARAM, LPARAM);
This one you used to register your class.
But then you've *defined* another WindowProcedure function with arguments:
WindowProcedure(HWND, WORD, WPARAM, LPARAM);
In C++, you've now got two functions with the same name, but different arguments due to function overloading. Solution: Change WORD to UINT.
2.) The window procedure shouldn't be infinitely recursive!
return WindowProcedure(hwnd, msg, wParam, lParam);
should be
return DefWindowProc(hwnd, msg, wParam, lParam);
because you should be letting the default window procedure handler handle anything that you don't.
Thanks.
I think I'll just go with dialogs and ResEdit for making GUI programs.
ourgets() is the function he wrote. His printf after the function call shows all the spaces.
redirect() is my function.
If I type "ls > test" the output I get is "The command you typed in is ls" and that's it.
int main() { char buf[1024]; // better not type longer than 1023 chars char aft[1024]; // this is to keep track of what is typed after a command usage(); for (;;) { *buf = 0; // clear old input printf("%s", "sh33% "); // prompt ourgets(buf); printf("cmd [%s]\n", buf); // just print out what we got as-is setArgsGiven(buf, arg, types, nArgsMax); [B] for(int i=0; i<1024; i++) { if(buf[i] == '>') { redirect(buf); } }[/B] int k = findCmd(buf, types); if (k >= 0) invokeCmd(k, arg); else usage(); } } void ourgets(char *buf) { fgets(buf, 1024, stdin); char * p = index(buf, '\n'); if (p) *p = 0; } void redirect(char *buf) { printf("The command you typed in is: %s \n",buf); }Working with the math is somewhat complicated (all Graphics APIs eventually require conversion to a matrix for vertex transforms) but I would say it is folly to let a math library handle your transforms without understanding what they mean. There is much, much more math besides linear algebra involved in working with a 3D graphics engine, depending on how deep you want to go.
If you are serious about learning some of the fundamentals of how modern graphics techniques are implemented, I would suggest trying to get a copy of this book. I found it to be a great reference for the underlying concepts of how modern graphics engines are created, and a good stepping stone toward more complex techniques.
After the math, the most complicated thing(or at least what I spend the most time doing) is figuring out how best to organize data so that you send the least amount of data to the GPU and minimize sync times between the CPU and GPU. This is actually why I prefer DirectX to OpenGL, in my experience DirectX gives a much better interface to the more advanced features of modern graphics hardware. Also HLSL is a massively better shading language than GLSL.
Also, I really quickly compiled that code, removing all the functions that weren't defined, I got the expected result.
cmd [ls > test]
The command you typed in is: ls > test
The only difference is that I had to find the newline myself rather than use his index operator. Just a nitpicky note, but you seem to have a bit of an indenting/curly brace problem starting with the closing curly brace of the inner for loop. I thought for a moment that your command finding operations were taking place inside that inner for loop for a moment.
I'm still learning/brushing up on C#. It seems like anonymous delegates and lambda expressions are pretty much the same thing. Am I missing something? Are there any times where one would be more beneficial than the other?
Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
Lambas are essentially sugar; the compiler can decompose them into anonymous delegates, so in that sense the benefit is merely that they are a cleaner and more concise way of writing equivalent functionality.
But the compiler can also decompose them into expression trees, so in that sense they are more versatile than anonymous delegates.
for(int i=0; i<1024; i++) { if(buf[i] == '>') { printf("i = %d \n",i); printf("%s\n",buf); i+=2; while(buf[i] != ' ') { aft[j] = buf[i]; i++; j++; } printf("This is inside the if statement\n"); printf("First part: %s Second part: %s \n",buf,aft); redirect(buf); } }Why does buf change???? The first printf for buf gives me whatever I typed in. The second one gives me gibberish. I really should just become an IT guy because this software development stuff isn't working out for me.
When you run into a problem like this, it's good to whip up an outline where you describe what you want to happen at each step in English.
edit:
Here's an example using an assignment I did for scripting class:
while(buf != ' ' && buf != '\0')
if you don't do this, you're gonna keep reading random memory past the end of buf until you happen upon a character that evaluates to ' '
int main() { char buf[1024]={0}; // better not type longer than 1023 chars, set all to 0. char aft[1024]={0}; // this is to keep track of what is typed after a command int j=0; usage(); for (;;) { printf("%s", "sh33% "); // prompt ourgets(buf); printf("cmd [%s]\n", buf); // just print out what we got as-is if (buf[0] == 0) continue; if (buf[0] == '#') continue; // this is a comment line, do nothing if (buf[0] == '!') // begins with !, execute it as system(buf + 1); // a normal shell cmd else { setArgsGiven(buf, arg, types, nArgsMax); for(int i=0; i<1024; i++) { if(buf[i] == '>') { printf("i = %d \n",i); printf("%s\n",buf); i+=2; while(buf[i] != ' ') { aft[j] = buf[i]; i++; j++; } printf("First part: %s Second part: %s \n",buf,aft); redirect(buf); } } int k = findCmd(buf, types); if (k >= 0) invokeCmd(k, arg); else usage(); } } }This is for my Operating Systems class. We're supposed to be making our own small OS. I am trying to get the '>' (redirect) working. But BEFORE I do that I need to get the commands split up. If someone types "ls > test.txt" I want to take the output of ls from our virtual disk and put it into the file test.txt on the real hard drive. The problem is that I don't know how to split it up. I need to be able to say "Hey, they typed in '>' which means there are two arguments, split them up and do the job".
Wish I could... The professor wrote everything and this is just a small part of a larger program. The entire thing looks terrible but I am trying to work with what I've got.
buf = buffer, what the user types in (he wrote)
aft = after, after the '>' (I wrote)
ourgets() = gets the input from the user
sh33% = no idea why he uses this, but it's the output for the user to type something in
arg, types, nMax = no idea what they are
while(buf[i] != ' ' && buf[i] != '\0') { aft[j] = buf[i]; i++; j++; } aft[j] = '\0';gives meOh sweet it does. Thanks
Oops sorry. I'm being completely vague when I respond and I shouldn't. This is what happens on my machine:
It really works on your computer?
Oh man lazerbeard that's what it was. I knew it had to be an initialization thing, and of course I didn't look at j. Thank you sir.
Awesome! Thanks
Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
I'm using dup2 (if anyone knows what that is...) to redirect the output from one file to another file. The problem is, after I use dup2 it basically shuts off the entire output of the program from then on. Does anyone know how to get the dup2 back? I'll post my redirect function:
void redirect(char *bef, char *aft) { int fd; int k = findCmd(bef,types); if(k >= 0) { fd = open(aft, O_CREAT | O_WRONLY); close(1); dup(fd); invokeCmd(k,arg); } }bef is the string before the '>' and aft is the string after the '>'; findCmd returns -1 if it can't find the command put in by the bef.