Jump to content
  • Advertisement
Sign in to follow this  
Pipes McGee

Newb to C, have a few questions + code.

This topic is 4282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was using this (all the code is on that page) tutorial and ran into a bit of a pickle. You see (I'm using Ubuntu [XP Home on dual-boot]), when I try to compile util.c I get this error message:
util.c: In function ‘bubble_sort’:
util.c:4: error: parameter ‘rand_seed’ is initialized
util.c:9: error: syntax error before ‘{’ token
Any advice? I have it exactly as shown in the tutorial. Also, do any of you have any better C (not C++) resources? I've been having some fun with this one, but I guess I can't rely on buggy code, no? Much thanks in advance. :)

Share this post


Link to post
Share on other sites
Advertisement
At a glance, the code on the page looks okay.

Why don't you paste the code you actually have, perhaps you made a transcription error?

Share this post


Link to post
Share on other sites
Here's the code for util.c:

/* util.c */
#include "util.h"

int rand_seed=10;

/* from K&R
- produces a random number between 0 and 32767.*/
int rand()
{
rand_seed = rand_seed * 1103515245 +12345;
return (unsigned int)(rand_seed / 65536) % 32768;
}

void bubble_sort(int m,int a[])
{
int x,y,t;
for (x=0; x < m-1; x++)
for (y=0; y < m-x-1; y++)
if (a[y] > a[y+1])
{
t=a[y];
a[y]=a[y+1];
a[y+1]=t;
}
}

Share this post


Link to post
Share on other sites
It compiles fine with gcc as well. I suspect that you need to change compilers, not tutorials.

EDIT: Which version of gcc are you running?

Share this post


Link to post
Share on other sites
Plus... I would suggest switching tutorials anyways. For something aimed at new developers that syntax is horrible. The variables names are terrible and the lack of curly braces on a pair of nested loops is unforgivable. Its a needless complexity to someone new to programming and for the most part is just lazy anyways.

Share this post


Link to post
Share on other sites
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

I have no idea what could be causing that problem. Anyway, I found a book at my library called C Primer Plus 5th Edition (2005), so I'm going to give that a go. Hopefully it will be more in depth than the tutorial I was using.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!