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. :)
Newb to C, have a few questions + code.
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:
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?
Why don't you paste the code you actually have, perhaps you made a transcription error?
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; }}
Ok, so it must be something local to gcc. I really like the tutorial I was using too, I wonder what the problem might be.
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?
EDIT: Which version of gcc are you running?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement