Sign in to follow this  

Newb to C, have a few questions + code.

This topic is 4093 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
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
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

This topic is 4093 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this