NO

Author Topic: New Pelles and C Learner  (Read 6147 times)

shazam

  • Guest
New Pelles and C Learner
« on: June 19, 2011, 09:46:40 PM »
Hello All  :D

Introducing myself

I bought C for dummies and found Pelles C by googling (I like that Pelles is C99)

I'm new to programming and have always wanted to learn C

OK.....off to chapter 1  ;D 

CommonTater

  • Guest
Re: New Pelles and C Learner
« Reply #1 on: June 19, 2011, 10:28:56 PM »
Welcome aboard...

C for Dummies isn't the best start you can have, but it's better than no start.  Just go through, do the exercises and play with the code a bit then move on to the next section... You'll do fine.

Also, make good use of the Pelles C helpfile... This is probably the best documented implementation of C-99 I've ever seen.  The help file is extremely well done.  (Thank you Pelle!)

shazam

  • Guest
Re: New Pelles and C Learner
« Reply #2 on: June 21, 2011, 02:53:30 AM »
Thanks for the feedback CT  :)

I bought the Dummies book because I was hoping...well....the author would teach me as a dummy  ;D

But I see he is using gets() and puts() alot...and from what I have googled .....those are frowned upon?

Maybe I'm so new that I shouldnt worry about it right now?

Hey at least I got "Hello World!" to finally work in a console app  ;D

CommonTater

  • Guest
Re: New Pelles and C Learner
« Reply #3 on: June 21, 2011, 06:22:19 AM »
Hello World is the standard first program for C programmers.  Even the advanced ones will write it as a quick way to test a new compiler setup.  So now that you've got that under your belt, it's on to the next section.

Yes, C4D does use gets() and puts() rather a lot.  It's not a problem really.  The frowning is because gets() is prone to overruns... fgets(dst,size,stdin) is a good replacement for gets(dst) as it has a length spec for the string.  printf() is generally considered the better replacement for puts() because puts() includes a newline sequence that is not always desirable... although I use puts a lot when troubleshooting with few or no problems.  (Look these up in the Pelles C help file for more info)

My suggestion would be to cultivate good habits as early as possible.  It's much easier than unlearning bad habits later.  So as you identify these things, you should adopt them... think of yourself as editing the book :D

Of course there is considerable expertise here to help you along.  In fact half these guys make me look like a beginner.

nandagopalrl

  • Guest
Re: New Pelles and C Learner
« Reply #4 on: January 24, 2012, 10:00:20 AM »
I am new to C and pelles - C, i am using windows 7 and virtual box buggs me so i installed pelles - c, i have been working only with borland C & CPP compiler,so i find it very hard to start with Pelles - C so some help please..

my problem for example - i tried to execute " HELLO WORLD" program to check how pelles - C works, but it wont accept clrscr, getch and SCANF!! void main is ot allowed, it is int main(viod)... i am a borland guy so please help me starting with pelles - C

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: New Pelles and C Learner
« Reply #5 on: January 24, 2012, 10:50:34 AM »
Have you look at PellesC excellent help file ?
search clrscr from there.

use #include <conio.h>

_clrscr function not standard C so you can use option -Go Define compability names
if you want to use clrscr() without underscore.

May the source be with you

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: New Pelles and C Learner
« Reply #6 on: January 24, 2012, 11:06:24 AM »
my problem for example - i tried to execute " HELLO WORLD" program to check how pelles - C works, but it wont accept clrscr, getch and SCANF!! void main is ot allowed, it is int main(viod)... i am a borland guy so please help me starting with pelles - C
For me it works. If you compile via IDE you should select in the project options for the compiler "built compatibility names" - if you you use the command line you should use the option "-Go".
For SCANF you must use small letters -> scanf().
If you include conio.h should not get warnings.
best regards
 Alex ;)

CommonTater

  • Guest
Re: New Pelles and C Learner
« Reply #7 on: January 24, 2012, 12:28:11 PM »
I am new to C and pelles - C, i am using windows 7 and virtual box buggs me so i installed pelles - c, i have been working only with borland C & CPP compiler,so i find it very hard to start with Pelles - C so some help please..

my problem for example - i tried to execute " HELLO WORLD" program to check how pelles - C works, but it wont accept clrscr, getch and SCANF!! void main is ot allowed, it is int main(viod)... i am a borland guy so please help me starting with pelles - C

Lots  of people moving up from Turbo C or Borland TC++ run into these problems.  It's about the standards used...  Borlands products predate modern standards so you could get away with a lot of pretty strange stuff whereas Pelles C is C99 standard and will, to some degree, enforce compliance with that standard.

For example:  void main () is not a good idea because main() is expected to return an errorlevel back to the operating system.  Also in C99 the a function with () is allowed to accept any number or type of parameters where a function that accepts no parameters is written as (void)... So the correct form is int main (void) and it returns 0 for success.

In C99 your "hello world" program looks like this...
Code: [Select]
#include <stdio.h>

int main(void)
  {
     printf("Hello World!\n");

     return 0;
  }

If you start the IDE click on following chain...

Help -> Contents -> (help window opens) Contents -> Integrated Environment ->  POIDE Integrated Envifonment -> Your First Project : Hello World

... you will find a nice little tutorial on how to create your first project.

While you are in the help file, spend some time familiarizing yourself with it.  It's going to be your best friend when writing C99 programs in Pelles C... It's all there... complete information on the IDE, C99, the command line tools, every library function (both standard and extended). 
 
Also, be aware that placing your text cursor on a coloured keyword and pressing F1 will fetch help on that keyword for you.  (Very handy!)
 
Pelles C does provide the non-standard conio.h ... but most C99 compilers do not.  So I would strongly suggest that instead of trying to make Pelles work like Turbo C... you should learn to do things the new way since that's how you write the best, most portable, code.
 
If you notice, all non-standard functions are clearly marked in the help file, and their names always begin with an underscore.  This is to ensure that you know you are writing code that may not work on a different compiler. 
 
As the others have suggested, you can use the "Define Compatibility Names" option in Project -> Project Settings -> Compiler to remove the leading underscore, but be aware this will mask compatibility issues and may result in code that produces huge numbers of errors on other compilers.
 
 
I'm very aware that some backwards schools (particularly in India) are still teaching with the older compilers and standards.  It is unfortunate that students get this "kick in the groin" realization that most of what they learned is next door to useless to them with modern tools.  You will have to make a lot of adjustments to get up to speed on C99... and, yes, before you say it... there was no excuse to not teach you C99 from the beginning, it's been around for over a decade.
 
« Last Edit: January 24, 2012, 12:52:37 PM by CommonTater »