Qbasicnews.com

Full Version: C!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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....
C without pointers = Qbasic Wink

Learn pointers... NOW!
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)
Quote: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...)
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.
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...
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.
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...
Quote: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.
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++?
Pages: 1 2