Qbasicnews.com
November 11, 2019, 09:51:17 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: C!  (Read 7017 times)
Shogun
Ancient QBer
****
Posts: 411



C!
« on: January 29, 2003, 03:33:18 PM »

I started learning it about a week ago mb and so far I LOVE IT itīs soooooooooooo awsome!!!!!! everyone should only code in C! although pointers are a nightmear....
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
C!
« Reply #1 on: January 29, 2003, 03:46:18 PM »

C without pointers = Qbasic Wink

Learn pointers... NOW!
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Agamemnus
x/ \z
*****
Posts: 3491



i
« Reply #2 on: January 29, 2003, 03:48:25 PM »

I don't like the semicolons or the brackets, though.

No easy way to use print screens and stuff...

 :bounce:


This thing bounces once every 1/4 second for some reason. (Konqueror browser)
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
wizardlife
Na_th_an
*****
Posts: 1456


WWW
« Reply #3 on: January 29, 2003, 04:14:18 PM »

Quote from: "Shogun"
I started learning it about a week ago mb and so far I LOVE IT itīs soooooooooooo awsome!!!!!! everyone should only code in C! although pointers are a nightmear....


Don't try to learn pointers just for the hell of it. Learn them when you need them for something. I didn't learn them until I wanted to do linked tilesets for my scrolling engine. (I now feel that an array would have been more appropriate anyways, but it was fun at the time...)
Logged

LooseCaboose
I hold this place together
*****
Posts: 981



C!
« Reply #4 on: January 29, 2003, 08:43:41 PM »

Learn pointers, without knowledge of them you cannot effectively use C to write even the simplest of programs.

eg.
Code:

#include <stdio.h>

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


Doesnt use pointers right? Wrong. The definition of printf is:
Code:

int printf(const char *format, ...);


Almost all of the string functions use pointers (strcmp, strcpy, strlen, etc), as do most functions for doing anything useful, including dynamic memory allocation.

Even arrays in C are pointers, try the following code:
Code:

#include <stdio.h>

int main(void) {
  int a[10];
  int *p;

  a[0] = 10;
  a[1] = 15;
  /* An array variable is a pointer to its first element */
  p = a;
 
  /* Easy way */
  printf("a[0] = %d, a[1] = %d\n", a[0], a[1]);

  /* Pointer way */
  printf("a[0] = %d, a[1] = %d\n", *p, *(p + 1));
}


As Na_th_an said, if you dont want to learn pointers you shouldnt really be coding in C, use another language instead such as Qbasic or Java.

As for the brackets and semicolons, these are used to allow a single line of code to spread many lines of text (because the end of line is denoted by a semicolan). The brackets are used for grouping blocks of code, ie functions, if statements, loops etc. But can also be used to introduce variables into a only part of a block: eg.
Code:

#include <stdio.h>
int main(void) {
  int a = 10;
  printf("a = %d\n", a);

  {
    int b = 5;
    printf("a = %d, b = %d\n", a, b);
  }
}


If you really cant stand them you can alway use a little preprocessor magic to get some pseudo-basic syntax. This isnt really a good idea and will cause you problems in the long run, but its a nice trick:
Code:

#define DIM(x) int x;
#define IF if(
#define ELSE } else {
#define ELSEIF } else if(
#define THEN ) {
#define ENDIF }

#include <stdio.h>

int main (void) {
  DIM(x)
  x = 5;

  IF X = 5 THEN
    x = x + 1;
  ELSEIF x = 10 THEN
    x = x + 2;
  ELSE
    x = x - 2;
  ENDIF
}

When passed through the preprocessor will give (ignoring stdio.h):
Code:

#include <stdio.h>

int main(void) {
  int x;
  x = 5;
 
  if( x = 5 ) {
    x = x + 1;
  } else if( x = 10 ) {
    x = x + 2;
  } else {
    x = x - 2;
  }
}


Anyway, all languages are different and all have specific tasks for which they are a better choice over other languages. C is a /very/ powerful and flexible language, but it can also be very complicated to learn and use effectively. If you are going to learn C, learn it properly and play around with pointers (try and use an OS with memory protection such as WinNT or Unix if you can, rogue pointers can crash a DOS or Win9x system quite easily. Get an introduction to C book out of the library and read it cover to cover. Happy coding.
Logged

esus saves.... Passes to Moses, shoots, he scores!
Shogun
Ancient QBer
****
Posts: 411



C!
« Reply #5 on: January 30, 2003, 06:28:41 AM »

Iīve alrady got a C book (C for real dummies or somthing like that) and I`m using a Unix computer to writh it and I`m gonna learn pointers itīs just a really confusing...but I guess that when I know how to use them they woinīt be anymore...
Logged
Hard Rock
I hold this place together
*****
Posts: 775


WWW
C!
« Reply #6 on: January 30, 2003, 12:48:23 PM »

The main reason you would WANT to code in c and not qb, is becuase pointers are the coolest thing ever. Pointers make things so much easier and cooler.... you get the idea.
Logged

b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror]
Stop Double Posts!
Whats better? HTML or Variables?
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
C!
« Reply #7 on: January 30, 2003, 12:48:28 PM »

I also try to learn C++ as it tend to be the "best" and "most used"
language nowdays (don't shoot me for saying that in a QB forum)
but pointers is hard to understand
I how to use them now,
but then by book starts to go on
about pointers to classes at the free memory
and such stuff *phew*

btw Do anyone here have any tips wich is the best editor/compiler
best way to learn how to program API/Graphics
(the book only teaches the "theoretical" parts and some simple
console stuff = std::cout std::cin...
Logged

/post]
wizardlife
Na_th_an
*****
Posts: 1456


WWW
C!
« Reply #8 on: January 30, 2003, 04:29:12 PM »

Quote from: "red_Marvin"
btw Do anyone here have any tips wich is the best editor/compiler best way to learn how to program API/Graphics (the book only teaches the "theoretical" parts and some simple console stuff = std::cout std::cin...


Before the hack, I was pointed to Bloodshed Software's Dev-C++. I've enjoyed using it, and it will compile DOS or windows proggies. If you're interested in OGL, I could send you the stuff I'm working on. It's very basic, and thus good for learning...

If you want to do DOS games or whatever, there's loads of dos libs like Future and DQB for C. Just google search.
Logged

red_Marvin
Na_th_an
*****
Posts: 1509



WWW
C!
« Reply #9 on: January 30, 2003, 05:35:26 PM »

The world is small wiz I also use Bloodsheed Dev C++
I've heard that many c/c++ games is made with some allegro
library and/or djgpp compiler... Is that good? can you use allegro on another compiler than djgpp?
Is allegro c/c++?
Logged

/post]
Hard Rock
I hold this place together
*****
Posts: 775


WWW
C!
« Reply #10 on: January 30, 2003, 06:14:27 PM »

Quote
Bloodshed Software's Dev-C++. I've enjoyed using it, and it will compile DOS


I dont think so on that one, DJGPP compiles DOS programs, dev-c++ does not. Dev C++ compiles windows consoles, eg text only things and do not properly support many dos functions like conio.h among things. Its only there for backwards compatibity.

There might be a way to get it to compile in dos however, as DJGPP and dev-c++ both use the gcc compiler, but im not really sure on that one.  i think there seperate ports, as DJGPP has random() as well as rand(), but dec-c++ does not.


Quote

I've heard that many c/c++ games is made with some allegro
library and/or djgpp compiler... Is that good? can you use allegro on another compiler than djgpp?

*sigh* the whole point of allegro is so that it will work on many different OS's and compilers....

Itll work with msvc, devc++,djgpp,and borland(very buggy) on the windows/dos side. It also workds under linux, and a little for the mac.

http://alleg.sf.net //official page
http://allegro.cc   //game depot,probably best allegro site,down right now


[edit]
Well might as well promote my game, i did this for a christmas contest, it uses allegro and was compiled both with dev-c++ for the windows .exe and djgpp for the dos version, both are in the download.

Get it here: http://stars.hybd.net/games/ponguc.html
Logged

b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror]
Stop Double Posts!
Whats better? HTML or Variables?
LooseCaboose
I hold this place together
*****
Posts: 981



C!
« Reply #11 on: January 30, 2003, 09:08:14 PM »

Compiler: gcc
Debugger: gdb
Editor: xemacs
Aditional tools: GNU

The whole lot are cross-platform, free, open source and very nice to work with (IMHO). I dont really use libraries with C because most of the coding I do with it is very low level stuff ;-)

I really do not like C++, it is a horrible language that attempts to take the best of C and OO programming and mash it all together. It has a poorly designed syntax which causes problems and all other sorts of nonsense. Java is a far better designed language, and you can get compilers for Java to produce OS specific object files rather than VM byte code.

As for the random()/rand() issue, rand() conforms to SVID 3, BSD 4.3 and ISO 9899, while random() only conforms to BSD 4.3. So I would go with the rand() family to ensure a high level of portability, although random() returns a long int, whilst rand() only returns an int.
Logged

esus saves.... Passes to Moses, shoots, he scores!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!