Page 1 of 1 [ 11 posts ] 

gramirez
Veteran
Veteran

User avatar

Joined: 9 Nov 2008
Age: 30
Gender: Male
Posts: 1,827
Location: Barrington, Illinois

03 Feb 2009, 9:03 pm

I recently started playing around with C. I'm not really doing anything, except copying code exactly as I see it in the book. I have my compiler program (Bloodshed C something or other) setup, and I type in the code with no errors. When I build the program and execute it, I see the windows command prompt pop up for a split second, then goes away. Why?


_________________
Reality is a nice place but I wouldn't want to live there


ToadOfSteel
Veteran
Veteran

User avatar

Joined: 23 Sep 2007
Age: 36
Gender: Male
Posts: 6,157
Location: New Jersey

03 Feb 2009, 9:35 pm

If you're running it in windows, that's because the command prompt is called up to run the program, then quickly execute it and make the window disappear.

If you want the window to stay on, go to start->run. In the dialog box, enter "cmd". That will call up the command prompt from which you can execute the program and keep the results on screen.



computerlove
Veteran
Veteran

User avatar

Joined: 10 Jul 2006
Age: 123
Gender: Male
Posts: 5,791

04 Feb 2009, 12:08 am

get a Mac


_________________
One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

04 Feb 2009, 8:35 am

BTW: I never would recommend C as a beginner programming language.(*) There was some time ago a thread at slashdot regarding this issue:

http://ask.slashdot.org/article.pl?sid=05/08/11/1951203

My personal recommendation is Pascal - I am not talking about the different dialects (Borland, etc.), but about ISO-Pascal. You will learn almost automatically a proper and structured programming style. If you want to start directly with object-oriented languages, you may consider Ada or Modula.

---
Footnote:
(*) It is even for some theorist not clear to count C under the label "higher programming language". Notabene N. Wirth raised a lot of objections against C (and C++), because both languages are not restricted enough.



kalantir
Veteran
Veteran

User avatar

Joined: 25 Dec 2008
Gender: Male
Posts: 712
Location: Redmond, WA USA

04 Feb 2009, 9:07 am

Nice choice of compiler btw. Thats what I use when I'm on windows.
try adding

Code:
get();

at the end of the program. That will make it wait for input before continuing. (ie, untill the user hits enter)

I also would not recommend C. Its very primitive and outdated imho. I much prefer C++. It can do everything that C can do, the exact same way that you'd do it in C. Plus much much more. In C, you'll spend time writing functions to do basic things that C++ can handle right off the bat. People will try to tell you that C++ is too complicated. This is untrue. If you can handle C, you can handle C++. Its easier, not harder. Many people might recommend Python. I have nothing against Python, and while its true that its easy to learn and use, bear in mind if you mess with it that its not technically a "programming language". It is actually a scripting language and wont ever be able to achieve the same speed and efficiency as most actual programming languages.(Although I'll admit its fast for what it is)
Overall, the most practical languages to learn are probably C++, C#, and Java. This is, of course, opinion.


_________________
2101729 Kalantir-Bar-Orc-Mal-Cha escaped the dungeon


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

04 Feb 2009, 9:45 am

kalantir wrote:
Nice choice of compiler btw. Thats what I use when I'm on windows.
try adding
Code:
get();

at the end of the program. That will make it wait for input before continuing. (ie, untill the user hits enter)

I also would not recommend C. Its very primitive and outdated imho. I much prefer C++. It can do everything that C can do, the exact same way that you'd do it in C. Plus much much more. In C, you'll spend time writing functions to do basic things that C++ can handle right off the bat. People will try to tell you that C++ is too complicated. This is untrue. If you can handle C, you can handle C++.


That's is a common misconception: C++ has a much stricter type handling. The following line would compile flawless in C;

Code:
 aArray = calloc (iSizeArray, sizeof (double));
if (aArray == NULL) ErrorHandler ();

/* some code */

if (aArray != NULL) free (aArray);


to compile this in C++ you would need to cast the void-pointer:

Code:
 aArray = (double *) calloc (iSizeArray, sizeof (double));
if (aArray == NULL) ErrorHandler ();

/* some code */

if (aArray != NULL) free (aArray);


but the most C++-programmer would not consider the code above as "proper" C++; but something like this:

Code:
try { aArray = new double [iSizeArray];}
catch (ExceptionHandler::GetType clExcpetion) { ExceptionHandler::HandleEception (clExcpetion) }

// some code

delete [] aArray;


kalantir wrote:
Its easier, not harder.


You also need to learn concepts which are totally alien to C, like classes, templates, different kind of class hierarchies (including concepts like friend or protedted).

kalantir wrote:
Overall, the most practical languages to learn are probably C++, C#, and Java.


The most important issue for a beginner is to learn a strict idea about data and control flow. Here is Pascal still the best language, even it more than unlikely that you will write anywhere professional anything in ISO-Pascal any more.



Death_of_Pathos
Deinonychus
Deinonychus

User avatar

Joined: 7 Nov 2008
Age: 37
Gender: Male
Posts: 351

04 Feb 2009, 2:03 pm

C isn't so great of a first language. C# is better (I have a personal weakness for it) but Python is probably the best. Pascal was my "first" and I can vouch for it being a very good start.

Disclaimer: I am not pro when it comes to coding.



kalantir
Veteran
Veteran

User avatar

Joined: 25 Dec 2008
Gender: Male
Posts: 712
Location: Redmond, WA USA

04 Feb 2009, 4:38 pm

Dussel wrote:
You also need to learn concepts which are totally alien to C, like classes, templates, different kind of class hierarchies (including concepts like friend or protedted).

Someone who's new to the language doesn't have to jump right into OOP concepts. All I know is, when I switched from C to C++, I just regretted using C in the first place.

Dussel wrote:
That's is a common misconception: C++ has a much stricter type handling. The following line would compile flawless in C;

Ok, theres a few exceptions. enum also operates a little differently, as do a few other things. But for the most part, anything you write in C, you could compile with a C++ compiler if you wanted to

Code:
aArray = calloc (iSizeArray, sizeof (double));
if (aArray == NULL) ErrorHandler ();

/* some code */

if (aArray != NULL) free (aArray);


Code:
try
{
    aArray = new double [iSizeArray];
}
catch (ExceptionHandler::GetType clExcpetion)
{
    ExceptionHandler::HandleEception(clExcpetion)
}

// some code

delete [] aArray;


Exception handling is another concept that someone new to the language wouldn't jump right into. But in any case, I'll take the C++ version any day. (I formatted it differently because I find it easier to read that way) new and delete are two of my favorite additions to C++;
Ive never used Pascal, so I have nothing to say about it. My stepdad seems to like it though, and I trust his opinion about computer-related things. He's the one who got me into programming in the first place.


_________________
2101729 Kalantir-Bar-Orc-Mal-Cha escaped the dungeon


gramirez
Veteran
Veteran

User avatar

Joined: 9 Nov 2008
Age: 30
Gender: Male
Posts: 1,827
Location: Barrington, Illinois

04 Feb 2009, 4:45 pm

computerlove wrote:
get a Mac

Have you seen my other posts? :) :roll:

I did the cmd thing and it worked!

I appreciate all of your help, but I really don't know what language I should be starting on. Something that will work on older Mac would be nice. I just want to be able to write useful programs.


_________________
Reality is a nice place but I wouldn't want to live there


Dussel
Veteran
Veteran

User avatar

Joined: 19 Jan 2009
Age: 60
Gender: Male
Posts: 1,788
Location: London (UK)

04 Feb 2009, 5:00 pm

kalantir wrote:
Dussel wrote:
You also need to learn concepts which are totally alien to C, like classes, templates, different kind of class hierarchies (including concepts like friend or protedted).

Someone who's new to the language doesn't have to jump right into OOP concepts. All I know is, when I switched from C to C++, I just regretted using C in the first place.


I use both often in a mix-up. Sometime the C-concepts are just to handy, sometime the C++-concepts are better. I would not like miss the pointer handling C++ inherited from C and often a printf or fopen is just simpler to handle than the C++-streams. It really depends on the situation and task.

kalantir wrote:
Dussel wrote:
That's is a common misconception: C++ has a much stricter type handling. The following line would compile flawless in C;

Ok, theres a few exceptions. enum also operates a little differently, as do a few other things. But for the most part, anything you write in C, you could compile with a C++ compiler if you wanted to

Code:
aArray = calloc (iSizeArray, sizeof (double));
if (aArray == NULL) ErrorHandler ();

/* some code */

if (aArray != NULL) free (aArray);


No - just tested (gcc 4.3.2 on Linux 2.6.26)
Code:
bool Matrix::CreateRandomContence (void)
{
        int    iCountTotal;

        iCountTotal = iCountRowsCols * iCountRowsCols;

        aEntries = calloc (iCountTotal, sizeof (double));
//        aEntries = (double *) calloc (iCountTotal, sizeof (double));
        if (aEntries == NULL)
        {
                ErrorHandler::FatalError ("<Matrix::CreateRandomContence> Can not allocate Heap\n");
                return false;
        }
        else
        {
                for (int iLoop = 0; iLoop < iCountTotal; iLoop++)
                        aEntries [iLoop] = RandomCover::GetDouble ();

                return true;
        }
}


creates the following error-message:
Code:
Matrix.cpp
Matrix.cpp: In member function ‘bool Matrix::CreateRandomContence()’:
Matrix.cpp:130: error: invalid conversion from ‘void*’ to ‘double*’


kalantir wrote:
Exception handling is another concept that someone new to the language wouldn't jump right into. But in any case, I'll take the C++ version any day. (I formatted it differently because I find it easier to read that way) new and delete are two of my favorite additions to C++;


How else you can check that e.g. a new-operator was successful? Even if no extensive functionality is build in the new operator, you need to check at least that the heap has been allocated.

I totally agree that such concepts are not suitable for someone how learns his first programming language. Therefore a more simple language, e.g. Pascal, is fine.



computerlove
Veteran
Veteran

User avatar

Joined: 10 Jul 2006
Age: 123
Gender: Male
Posts: 5,791

04 Feb 2009, 5:31 pm

gramirez wrote:
computerlove wrote:
get a Mac

Have you seen my other posts? :) :roll:

I was j/k


_________________
One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.