• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

I'm tooling around with a trial of Visual Studio 2012 Professional, and so far, I do not like the UI changes. It seems different for the sake of being different, I don't know. Or maybe it's inline with their other product rollouts, but I'm not up-to-date on those, either. It's a departure. As a reference, I've used Visual Studio 2003 (limited exposure), 2005, 2008, and 2010 prior to this. I loved 2010's UI from the moment I started using it. I just don't have that same feeling from 2012. The learning curve from 2012 should be about the new features added to the languages, the powerful tools and features you can leverage. I would rather be on that learning curve, instead of figuring out what's what in the UI and dealing with changes to common dialog windows.

I'm particularly not happy with the lack of unit test features. I don't know if they've cut them back, or maybe it's just a version difference (I use 2010 Ultimate at work, and this is 2012 Professional), but it seems I just have less options for running and organizing tests. Where's my option to "run all tests / run tests in scope / run impact tests?" Where's my Test View where I can apply groupings to selectively run certain batches of tests? Where's my test output window where I can add/remove columns to display useful information? I don't think these were Premium/Ultimate features, but I could be wrong.
 

CrankyJay

Banned
I'm tooling around with a trial of Visual Studio 2012 Professional, and so far, I do not like the UI changes. It seems different for the sake of being different, I don't know. Or maybe it's inline with their other product rollouts, but I'm not up-to-date on those, either. It's a departure. As a reference, I've used Visual Studio 2003 (limited exposure), 2005, 2008, and 2010 prior to this. I loved 2010's UI from the moment I started using it. I just don't have that same feeling from 2012. The learning curve from 2012 should be about the new features added to the languages, the powerful tools and features you can leverage. I would rather be on that learning curve, instead of figuring out what's what in the UI and dealing with changes to common dialog windows.

I'm particularly not happy with the lack of unit test features. I don't know if they've cut them back, or maybe it's just a version difference (I use 2010 Ultimate at work, and this is 2012 Professional), but it seems I just have less options for running and organizing tests. Where's my option to "run all tests / run tests in scope / run impact tests?" Where's my Test View where I can apply groupings to selectively run certain batches of tests? Where's my test output window where I can add/remove columns to display useful information? I don't think these were Premium/Ultimate features, but I could be wrong.

I mentioned this previously, the TFS integration (if you use it) sucks...simply right clicking and finding what you need in context menus have been moved and buried elsewhere.

The new code diff tool is nice though.

I'm not a fan of the metro-style interface, I'm often confused what section of VS I am in.
 

qazqaNii

Member
are you using the designer to make this gui or are you writing it in code?

I am like trying both.. I put a pushButton on the designer in QT, go back to mainWindow.h and include my header that has my basic functions like add a new Game or something like that.

I create the pushButton in mainWindow.h, i.e.
Code:
public:
void on_pushButton_clicked()

Now that I have "implemented" the button in mainWindow.h I go to mainWindow.cpp, this is where the problem starts, I can't seem to understand what to do, in visual basic it was simple as hell but in here.. I just don't know how.

Lets say I got a Game.h that got functions like addGame(string newGame) or something like that shouldn't I then be able to call this function in mainWindow.cpp->in the function on_pushButton_clicked()?

I got all the functions already done, I just have to link them to the buttons but I fail to do so. :(
 
I am like trying both.. I put a pushButton on the designer in QT, go back to mainWindow.h and include my header that has my basic functions like add a new Game or something like that.

I create the pushButton in mainWindow.h, i.e.
Code:
public:
void on_pushButton_clicked()

Now that I have "implemented" the button in mainWindow.h I go to mainWindow.cpp, this is where the problem starts, I can't seem to understand what to do, in visual basic it was simple as hell but in here.. I just don't know how.

Lets say I got a Game.h that got functions like addGame(string newGame) or something like that shouldn't I then be able to call this function in mainWindow.cpp->in the function on_pushButton_clicked()?

I got all the functions already done, I just have to link them to the buttons but I fail to do so. :(
Well you need to include Game.h inside either in mainWindow.h or mainWindow.cpp for you to be able to access functions from Game.h.

Just a simple #include "Game.h" at the top should work. You're going to need to make your own callbacks using signals and slots in QT to add the custom code you need.

I think your problem here might be that you're trying to learn too much at once. QT is not an API that I'd say is very beginner friendly for people new to C++. You should learn C++ in simpler tutorials and such first. There are very common C++ design patterns that are used in QT's design and knowing such things will give you insight into what is actually going on.

BTW, make sure you're putting header guards on your header files. They prevent circular dependencies/inclusions. Google them to see how they work.
 
I'm learning about linked lists in C++ at the moment and its really kicking my ass lol

Making your own LinkedList class, even just for storing arbitrary data (ie not using templates) is a fantastic exercise for people new to pointers. Between the LinkedList assignment I did in C and the heap manager I wrote in assembly, all my fears about pointers were completely erased. It will come natural with time, so don't worry if you struggle now.
 
I'm learning about linked lists in C++ at the moment and its really kicking my ass lol

My data structures professor made our linked list assignment have the next link be every other element, and same for the previous element for each node. Then he made another modification about having a dummy node, and be circular. Needless to say it was a diabolical thing since we only had a week to implement it. Never again was I afraid of pointers after that.
 

BreakyBoy

o_O @_@ O_o
I recently started to learn C# for the hell of it (I pretty much have zero programming knowledge outside of Batch coding, which doesn't really count), and am using these videos: http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners

Does anyone know of any good free books, tutorials, websites, etc. that I could utilize for when I finish these videos?

I haven't checked to see if the links are still active, but this is usually a decent starting point for any language.
 
Making your own LinkedList class, even just for storing arbitrary data (ie not using templates) is a fantastic exercise for people new to pointers. Between the LinkedList assignment I did in C and the heap manager I wrote in assembly, all my fears about pointers were completely erased. It will come natural with time, so don't worry if you struggle now.

I bet that was a hell of a lot of fun.
 

billsmugs

Member
I recently started to learn C# for the hell of it (I pretty much have zero programming knowledge outside of Batch coding, which doesn't really count), and am using these videos: http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners

Does anyone know of any good free books, tutorials, websites, etc. that I could utilize for when I finish these videos?

Rob Miles Yellow Book is a great (free) book in PDF format for learning C#. I don't know how far beyond those videos it will go, but I used it on its own to learn the language and found it very clear and simple, with lots of info.

I'm still new to the language (and relatively new to programming in general, except for using GML in Game Maker and doing a C programming course at university), but I'm now making a game using PlayStation Mobile in C# and the Yellow Book is enough to answer 95% of the questions I encounter on basic C# concepts. The book starts from the most basic initialising of variables up to details on Threading and GUIs (I haven't actually read up the that point yet, but I've got through about 100 of the 201 pages and everything is explained clearly and with a bit of humour every so often, and it goes into plenty of detail on each topic and doesn't assume any previous knowledge).
 

leroidys

Member
Can anyone explain how this captures every possible binary tree for n nodes? I don't understand the recurrence relation. (It's the catalan series of numbers).

png.latex


EDIT: I think I FINALLY got it (I worked on this problem for several hours yesterday. Sometimes you just need to focus on something else for a while...)

So the two factors represent the left and right child of the parent node. The children range from 0 to n-1 nodes. So if we know how many arrangements of 0..n-1 nodes are possible, then we can just multiply every permutation the results together to find the total number of combinations.
 

squidyj

Member
I am like trying both.. I put a pushButton on the designer in QT, go back to mainWindow.h and include my header that has my basic functions like add a new Game or something like that.

I create the pushButton in mainWindow.h, i.e.
Code:
public:
void on_pushButton_clicked()

Now that I have "implemented" the button in mainWindow.h I go to mainWindow.cpp, this is where the problem starts, I can't seem to understand what to do, in visual basic it was simple as hell but in here.. I just don't know how.

Lets say I got a Game.h that got functions like addGame(string newGame) or something like that shouldn't I then be able to call this function in mainWindow.cpp->in the function on_pushButton_clicked()?

I got all the functions already done, I just have to link them to the buttons but I fail to do so. :(

To be honest I've never used the designer so I can't really speak to how that works but generally speaking there's 2 major concepts in QT, one being slots and signals, the other being widgets.

The window is a widget, it's menu is a widget, your button is a widget, pretty much all the UI elements you see are widgets

The other thing is slots and signals, Widgets have things called slots and things called signals

you can think of signals as things that get emitted for now as it seems unlikely that you would have to write your own. The basic button widget QPushButton has a signal called clicked(bool checked = false) (which it gets from QAbstractButton). Whenever you click that button the clicked signal is emitted but if it's not tied to any slots not much of anything is going to happen.

Slots are just functions that get called when a signal they are connected to is emitted. So you can easily write your own slot in your own class and connect the two.

connecting is pretty easy, you just need to use the connect function which is in QObject.

Of course saying all this can still be pretty confusing so here's an example I wrote up in a few minutes.

Consider first a potential header for a class called MyGame

Code:
#ifndef MYGAME_H 					//This is a header guard!
#define MYGAME_H 					//It helps with circular dependencies which can be nasty
#include <QObject>					//this is include QObject so we can do all sorts of interesting things with it				

class MyGame : public QObject				//my game inherits directly from QObject
{							//you need to inherit either directly or indirectly from QObject in order to be able to work with slots and signals
	Q_OBJECT					//this is a macro for the moc, we need it to be able to do slots and signals type stuff

public:							//declare all my public methods and fields
	void gameLoop();				//this is a public method in my class
public slots:						//now we declare slots
	void startGame();				//startGame is going to be our slot
signals:						//this is where would declare our own custom signals if we had any
};							//we don't have any
#endif							//This is where the header guard ends, at the end

And then a main function that would put that together with a button and into a window.

Code:
#include "MyGame.h"
#include <QApplication>			
#include <QtGui>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);							//make a new Qt application object that's going to hold everything for us
	QWidget window;									//make a window from a QWidget, there are also specific window classes
	MyGame *game = new MyGame();							//yep, that's a pointer to an instance of our game.
	QPushButton *myButton = new QPushButton("Start Game");				//create a new button, remember this is a pointer to a button
	
	QObject::connect(myButton, SIGNAL(clicked(bool)), game, SLOT(startGame()));	//this is how we connect the signal in the button to the slot in the game
					
	QHBoxLayout *mainLayout = new QHBoxLayout();					//and we'll make a layout, again with a pointer
											//The H in QHBox stands for horizontal
	mainLayout->addWidget(myButton);						//the arrow means a dereferencing is going on, we add the button to the layout
	window.setLayout(mainLayout);							//and then we set the layout of the window to the main layout.
	window.resize(window.sizeHint());						//set the size of the window, could pass a self-defined QSize object
	window.show();									//finally, display the window and all of its elements
	return a.exec();								//and enter the main loop of the program
}

The signal from the button is connected to the slot from the game so when you click the button, the signal is emitted and the method startGame() is called.

Obvious Disclaimer: while this code has the header declarations it lacks any definitions for the MyGame methods.
 

harSon

Banned
I'm trying to learn c# (my first stab at programming ever) and am using these videos as a jumping off point: http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners I'm currently on video 9 and am trying to practice what I've learned thus far by consolidating all of the concepts I've been introduced to into a program. This is what I have so far, but I was wondering: A) How I could make it so the user doesn't have to press Enter to move from the "Press C and ENTER" tidbit to the "Now that you've calculated..." chunk of code and B) I'm not sure why "That is incorrect." is returned when I enter in C given that my if/else statement. I'm sure the code is a mess, but I've only been doing this since Saturday. Feel free to give me some pointers though, it'd be appreciated!

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Algebra
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("What is the sum of 928 and 387?\n");
            string[] tests = { "A. 2872", "B. 3983", "C. 1315", "D. 1218" };

            foreach (string test in tests)
            {

                Console.WriteLine(test);

            }

            Thread.Sleep(800);
            Console.WriteLine("\nUse this calculator to find the answer. The equation is X + Y = Z, what is your X?");
            int x = int.Parse(Console.ReadLine());
            Console.WriteLine("Are you sure that " + x + " is the correct number?");
            string answer = Console.ReadLine();

            if (answer == "Yes")
            {
                Console.WriteLine("Okay, X is " + x + ". What is your Y?");
            }

            else
            {
                Console.WriteLine("Apologies. What is X then?");
                int x2 = int.Parse(Console.ReadLine());
            }

            int y = int.Parse(Console.ReadLine());
            Console.WriteLine("Are you sure that " + y + " is the correct number?");
            string secondAnswer = Console.ReadLine();
            if (answer == "Yes")
            {
                Console.WriteLine("Okay, Y is " + y + ". Press C and ENTER to calculate equation.");
                string response = Console.ReadLine();
                if (response == "C")
                {

                    int z = x + y;
                    Console.WriteLine("Your answer is " + z + ".");
                    Console.ReadLine();

                }
            }
            Thread.Sleep(800);
            Console.WriteLine("Now that you've calculated the equation, what is the sum of 928 and 387? (A, B, C or D)\n");
            Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
            Console.ReadLine();
            {
                Thread.Sleep(800);
                string finalAnswer = Console.ReadLine();
                string[] choices = { "That is correct.", "That is incorrect." };
                if (finalAnswer == "C")
                {
                    Console.WriteLine("{0}", choices);
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("{1}", choices);
                    Console.ReadLine();
                }

            }

        }
    }
}
 

Chris R

Member
I'm not quite sure what you are asking in part 1, but as for part 2 are you typing in c or C? Because the code is expecting "C" and not "c".
 

moka

Member
I'm not quite sure what you are asking in part 1, but as for part 2 are you typing in c or C? Because the code is expecting "C" and not "c".

He could look into converting the input into lowercase, then he only has to check for lowercase c and would allow the user to input in either lowercase or uppercase.

String.ToLower Method.
 

harSon

Banned
I'm not quite sure what you are asking in part 1, but as for part 2 are you typing in c or C? Because the code is expecting "C" and not "c".

As it stands now, when you go from:
Code:
{
                Console.WriteLine("Okay, Y is " + y + ". Press C and ENTER to calculate equation.");
                string response = Console.ReadLine();
                if (response == "C")
                {

                    int z = x + y;
                    Console.WriteLine("Your answer is " + z + ".");
                    Console.ReadLine();

                }
            }

to:

Code:
Console.WriteLine("Now that you've calculated the equation, what is the sum of 928 and 387? (A, B, C or D)\n");
            Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
            Console.ReadLine();
            {
                string finalAnswer = Console.ReadLine();
                string[] choices = { "That is correct.", "That is incorrect." };
                if (finalAnswer == "C")
                {
                    Console.WriteLine("{0}", choices);
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("{1}", choices);
                    Console.ReadLine();
                }

            }

The user has to press Enter to transition between the codes. I would like the transition to happen automatically. Sorry if that doesn't make sense, I'm not really privy to the terminology yet.

And as for the "C" aspect of my post, it doesn't matter whether I input a capital or lower case C, it still spits out "This is incorrect."
 
The user has to press Enter to transition between the codes. I would like the transition to happen automatically. Sorry if that doesn't make sense, I'm not really privy to the terminology yet.

And as for the "C" aspect of my post, it doesn't matter whether I input a capital or lower case C, it still spits out "This is incorrect."

Code:
 Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
 [B]Console.ReadLine();
 {[/B]
                string finalAnswer = Console.ReadLine();

Well, what are you trying to do in this bit of code? This is where I would be looking first. You would also benefit from printing out your "finalAnswer" or using the debugging tools in whatever you are writing the code in. Make sure it really is C at that point.
 

harSon

Banned
Code:
 Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
 [B]Console.ReadLine();
 {[/B]
                string finalAnswer = Console.ReadLine();

Well, what are you trying to do in this bit of code? This is where I would be looking first. You would also benefit from printing out your "finalAnswer" or using the debugging tools in whatever you are writing the code in. Make sure it really is C at that point.

The first part of the code is referring back to the array from the beginning of the code:

Code:
string[] tests = { "A. 2872", "B. 3983", "C. 1315", "D. 1218" };

and the second part is defining the string variable as whatever the User types in, which is to be used for the if/else statement right after.
 
The first part of the code is referring back to the array from the beginning of the code:

Code:
string[] tests = { "A. 2872", "B. 3983", "C. 1315", "D. 1218" };

and the second part is defining the string variable as whatever the User types in, which is to be used for the if/else statement right after.

Yep so the problem is you are doing two reads of the console when you only want one. I would say in your testing you are inputting C for the first test, and it is getting lost. This is why your finalAnswer is always empty.

Code:
Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
string finalAnswer = Console.ReadLine();

Some other comments:

* Make sure when you are checking for "Yes" you are not doing it in a case sensitive fashion. Also a good idea to test for "y" or "n" as people will commonly input them. Same for your C choice.
* This is especially important given the way you have designed the program. If you do not answer "Yes" it prompts again for X. This prompt does not additionally inform them to follow it with y. You should instead make these sections loops until the "yes" answer is given.
* If you type a letter for x or y it will break. Try to catch the exception (and loop until it is ok) or just read the input and convert it to a number yourself.
 

Naka

Member
As it stands now, when you go from:
Code:
{
                Console.WriteLine("Okay, Y is " + y + ". Press C and ENTER to calculate equation.");
                string response = Console.ReadLine();
                if (response == "C")
                {

                    int z = x + y;
                    Console.WriteLine("Your answer is " + z + ".");
                    Console.ReadLine();

                }
            }

to:

Code:
Console.WriteLine("Now that you've calculated the equation, what is the sum of 928 and 387? (A, B, C or D)\n");
            Console.WriteLine("{0}\n{1}\n{2}\n{3}", tests);
            Console.ReadLine();
            {
                string finalAnswer = Console.ReadLine();
                string[] choices = { "That is correct.", "That is incorrect." };
                if (finalAnswer == "C")
                {
                    Console.WriteLine("{0}", choices);
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("{1}", choices);
                    Console.ReadLine();
                }

            }

The user has to press Enter to transition between the codes. I would like the transition to happen automatically. Sorry if that doesn't make sense, I'm not really privy to the terminology yet.

And as for the "C" aspect of my post, it doesn't matter whether I input a capital or lower case C, it still spits out "This is incorrect."

If I understand what you are trying to accomplish you basically want to the code to execute as soon as they user enters "C" or "c"? If so it's entirely doable but probably a little more trouble than it's worth.

Here is one way you could possibly do it:
http://msdn.microsoft.com/en-us/library/system.console.keyavailable.aspx
 

Harpuia

Member
I rather confused as to why this won't work. Basically I want to keep start and end from being anything besides a number from 0 to 6, inclusive.

Code:
cin >> start >> end;
	
	while(((start < 0) && (start > 6)) && ((end < 0) && (end > 0)))
	{
		cout << "Please reenter a number from 0 to 5, inclusive.\n";
		cin >> start >> end;
	}
 

_Isaac

Member
I rather confused as to why this won't work. Basically I want to keep start and end from being anything besides a number from 0 to 6, inclusive.

Code:
cin >> start >> end;
	
	while(((start < 0) && (start > 6)) && ((end < 0) && (end > 0)))
	{
		cout << "Please reenter a number from 0 to 5, inclusive.\n";
		cin >> start >> end;
	}


You are checking if start is less than 0 AND also greater than six. How can it be less than zero and greater than six at the same time? It's impossible. You're doing the same thing with end. Try using OR somewhere in there like so:

Code:
cin >> start >> end;
	
	while(((start < 0) || (start > 6)) && ((end < 0) || (end > 0)))
	{
		cout << "Please reenter a number from 0 to 5, inclusive.\n";
		cin >> start >> end;
	}

Also your message says reenter a number from 0 to 5, but you're checking 0 to 6.
 
In JavaScript you can do the following.

Code:
this.fieldname = "something";
this.methodname();

For the equivalent.

Code:
this["fieldname"] = "something else";
this["methodname"]();

How can I do this similarly in Java and C#?
 

Kalnos

Banned
In JavaScript you can do the following.

Code:
this.fieldname = "something";
this.methodname();

For the equivalent.

Code:
this["fieldname"] = "something else";
this["methodname"]();

How can I do this similarly in Java and C#?

The same way? When writing a class if you use the 'this' keyword in Java/C# it does the same thing.
 
The same way? When writing a class if you use the 'this' keyword in Java/C# it does the same thing.

Doesn't work.

Code:
package test;

class Example {
    public String fieldname = "something";
    public void methodName() {
        System.out.println(this.fieldname);
    }
    public void test() {
        this["fieldname"] = "Hello";
        this["methodName"]();
    }
}

public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Example test = new Example();
        test.test();
    }
}
 

Rapstah

Member
I don't know any Javascript but why wouldn't you just refer to those as this.fieldname and this.methodName? You can't refer to methods or fields by string in Java, at least not in any way I've ever seen. (Not sure if that's what that syntax means in the first place, sorry.)
 

iapetus

Scary Euro Man
I don't know any Javascript but why wouldn't you just refer to those as this.fieldname and this.methodName? You can't refer to methods or fields by string in Java, at least not in any way I've ever seen. (Not sure if that's what that syntax means in the first place, sorry.)

Reflection allows you to do it, but it's a fairly convoluted process.
 
In JavaScript you can do the following.

Code:
this.fieldname = "something";
this.methodname();

For the equivalent.

Code:
this["fieldname"] = "something else";
this["methodname"]();

How can I do this similarly in Java and C#?

I think you need to look up the reflection api and examples.

Edit. Beaten
 

Ambitious

Member
About Face 3: The Essentials of Interaction Design, Alan Cooper

Just finished up a course on interaction design, and we mostly used this book for everything that wasn't design patterns. The author is the creator of VB so he knows what he's talking about.

See my second post, I've already got it. It's a really great resource.

Designing the User Interface: Strategies for Effective Human-Computer Interaction.

It's recommended by my Introduction to Human Computer Interaction professor, I haven't read it though but I've heard from many that it's good.

Thanks, I'll have a look.
 

Exuro

Member
Not sure if this is OT or not but does anyone have good resources on learning design patterns? Gotta order a book for class but in the mean time I need to go over the template method.
 
Not sure if this is OT or not but does anyone have good resources on learning design patterns? Gotta order a book for class but in the mean time I need to go over the template method.

Head First: Design Patterns is pretty good, especially if you need Java-specific examples
 
Can someone help me with this Applescript problem I'm having?

I'm trying to write a script that goes through a folder and gives me the duration of a MP4 file. Right now, I have the following in AppleScript:

Code:
do shell script "avconv -i " & quoted form of fullpath & " 2>&1 | grep 'Duration' | awk '{print $2}' | sed s/,// >>/Users/XXX/Documents/Misc_Documents/Movie_Clip_Durations.txt"

As you can see, I pass a variable called "fullpath" to the shell script. However, it doesn't work.

The reply from the Applescript event is:

Code:
do shell script "avconv -i '/Volumes/Hard Drive/New File/New File/My Movie.mp4' 2>&1 | grep 'Duration' | awk '{print $2}' | sed s/,// >>/Users/XXX/Documents/Misc_Documents/Movie_Clip_Durations.txt"

BUT BUT BUT

If I copy that bit of code into the terminal (minus the "do shell script" part and the beginning and ending quotes), it works perfectly. That is, if I copy:

Code:
avconv -i '/Volumes/Hard Drive/New File/New File/My Movie.mp4' 2>&1 | grep 'Duration' | awk '{print $2}' | sed s/,// >>/Users/XXX/Documents/Misc_Documents/Movie_Clip_Durations.txt

into Terminal, it works! I assume the problem is one of two things (or both). Either I can't use a path that is "quoted from" or that is within single quotes, or the spaces in the directories and files are causing an issue in the path, or both. I can't get this to work.

AND AND AND

I don't want to do this by having the Applescript tell Terminal to "do script" because if I do that, I have no way of knowing when the grep command finishes, which causes a lot of problems ( I tried this, and the only way I could get it to work is if I delayed 30 seconds after issuing that command, which made the entire script WAY too long after going through all the files in a folder).

I have to assume this is an easy fix. Any ideas?

Ok, I think it has to do with $PATH being different when I echo it in the shell script and when I do it from the terminal. Terminal is:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

shell script is:

"/usr/bin:/bin:/usr/sbin:/sbin"
 

usea

Member
Is there an easier way to join two LinkedLists in c# than iterating over the second and appending each link to the first list?
The normal List<T> class in C# has AddRange(IEnumerable) for adding one sequence to it. If you're determined to use LinkedList, your best options are:
1) Make an extension method on LinkedList for adding two of them together.
2) Use the IEnumerable extension method Concat and construct a new linked list from the result.

Here's an example of option 2:
Code:
var alpha = new LinkedList<int>();
alpha.AddLast(1);
alpha.AddLast(2);
alpha.AddLast(3);
var beta = new LinkedList<int>();
beta.AddLast(4);
beta.AddLast(5);
beta.AddLast(6);

alpha = new LinkedList<int>(alpha.Concat(beta));
//alpha now contains {1, 2, 3, 4, 5, 6}

You can implement option 1 however you want. The obvious way would be like this:
Code:
public static class LinkedListExtensions
{
	public static void AddRange<T>(this LinkedList<T> list, LinkedList<T> other)
	{
		foreach(var element in other)
		{
			list.AddLast(element);
		}
	}
}

void Main()
{
	var alpha = new LinkedList<int>();
	alpha.AddLast(1);
	alpha.AddLast(2);
	alpha.AddLast(3);
	var beta = new LinkedList<int>();
	beta.AddLast(4);
	beta.AddLast(5);
	beta.AddLast(6);
	
	alpha.AddRange(beta);
	//alpha now contains {1, 2, 3, 4, 5, 6}
}
 

Seanbob11

Member
Is there an easy way to read in numbers from a text file? The problem I have is that some are double digit numbers i.e. '40 12 6 15'. Because 'number' is an int it only brings in one at a time. Is there a way to include everything in infile until I reach a space?

I've got code like this:

Code:
int number;
ifstream infile ("C:\\C++\\numberstxt");
	
	if(!infile)
		{
			cout << "Can't open numbers.txt";
			cin >> hold;
			return(-1);
		}
        infile >> number;
 
Top Bottom